vjame

          優(yōu)化代碼是無止境的
          隨筆 - 65, 文章 - 9, 評論 - 26, 引用 - 0
          數(shù)據(jù)加載中……

          jstl標簽庫(3)


          jstl函數(shù)庫(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函數(shù)庫
           * 
          @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函數(shù)庫</title>
          </head>
          <body>
              
          <h1>測試jstl函數(shù)庫</h1>
              
          <hr>
              hello.length=(jsp腳本):
          <%=((String)request.getAttribute("hello")).length() %><br>
              
          <!--  hello.length(jstl函數(shù)庫,函數(shù)調(diào)用必須在el表達式中 前綴+冒號+函數(shù)名):${fn:length(hello) } -->
              hello.length(jstl函數(shù)庫,函數(shù)調(diào)用必須在el表達式中 前綴+冒號+函數(shù)名):${fn:length(hello) }
          <br>
              list.length:${fn:length(list) }
          <br>

          </body>
          </html>

          posted on 2009-07-27 11:10 lanjh 閱讀(301) 評論(0)  編輯  收藏 所屬分類: Java Web

          主站蜘蛛池模板: 兴宁市| 如东县| 根河市| 清原| 永登县| 民县| 宁化县| 本溪| 清苑县| 德州市| 沙湾县| 静海县| 梅河口市| 东山县| 青铜峡市| 伊宁县| 申扎县| 东城区| 寿阳县| 辽阳市| 育儿| 和林格尔县| 定襄县| 盐津县| 台山市| 左权县| 吉木萨尔县| 泸西县| 济南市| 子长县| 诸城市| 环江| 三门峡市| 元江| 桓台县| 临邑县| 隆安县| 东乡族自治县| 崇义县| 德庆县| 大邑县|