vjame

优化代码是无止境的
随笔 - 65, 文章 - 9, 评论 - 26, 引用 - 0
数据加载中……

jstl标签库(3)


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>

posted on 2009-07-27 11:10 lanjh 阅读(274) 评论(0)  编辑  收藏 所属分类: Java Web


只有注册用户登录后才能发表评论。


网站导航: