vjame

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

          jstl標(biāo)簽庫(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 閱讀(294) 評論(0)  編輯  收藏 所屬分類: Java Web

          主站蜘蛛池模板: 安徽省| 华宁县| 黄冈市| 汉沽区| 榆社县| 北京市| 渭源县| 龙州县| 临武县| 怀仁县| 德钦县| 东海县| 渭源县| 海门市| 龙里县| 怀仁县| 会泽县| 乌鲁木齐市| 康保县| 苍梧县| 屏边| 禄劝| 交口县| 应城市| 普定县| 高平市| 平阴县| 松溪县| 百色市| 三亚市| 靖西县| 洪雅县| 东莞市| 巴青县| 揭东县| 灵丘县| 民乐县| 阳江市| 焦作市| 岫岩| 盐源县|