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 閱讀(294) 評論(0)  編輯  收藏 所屬分類: Java Web

          主站蜘蛛池模板: 斗六市| 南开区| 石家庄市| 陈巴尔虎旗| 赤壁市| 晴隆县| 海口市| 上饶市| 霍邱县| 清苑县| 任丘市| 冷水江市| 金门县| 镇雄县| 潞城市| 苍溪县| 外汇| 南漳县| 万山特区| 阿克| 平江县| 宜川县| 临汾市| 泰州市| 越西县| 都匀市| 霍城县| 碌曲县| 伊宁县| 贵德县| 安西县| 宝兴县| 沅江市| 禹州市| 东丰县| 桃园县| 新津县| 阳东县| 葫芦岛市| 都兰县| 蓬莱市|