jstl函数库(fn)
Action
package com.lanjh.struts.action;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* 测试jstl函数库
* @author Administrator
*
*/
public class JstlFnAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("hello", "hello world");
List list = new ArrayList();
list.add("t1");
list.add("t2");
request.setAttribute("list", list);
request.setAttribute("name", "Tom");
return mapping.findForward("success");
}
}
struts配置
<action path="/jstlfn"
type="com.lanjh.struts.action.JstlFnAction">
<forward name="success" path="/jstl_fn.jsp"></forward>
</action>
JSP页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="GB18030"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>测试jstl函数库</title>
</head>
<body>
<h1>测试jstl函数库</h1>
<hr>
hello.length=(jsp脚本):<%=((String)request.getAttribute("hello")).length() %><br>
<!-- hello.length(jstl函数库,函数调用必须在el表达式中 前缀+冒号+函数名):${fn:length(hello) } -->
hello.length(jstl函数库,函数调用必须在el表达式中 前缀+冒号+函数名):${fn:length(hello) }<br>
list.length:${fn:length(list) }<br>
</body>
</html>