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

          主站蜘蛛池模板: 海丰县| 茌平县| 天气| 宁陕县| 台东县| 珠海市| 开封市| 洪洞县| 兴宁市| 三江| 镇赉县| 阳西县| 施秉县| 房产| 泰兴市| 磐安县| 浠水县| 闵行区| 常州市| 晋江市| 时尚| 会理县| 海南省| 宁城县| 岐山县| 克山县| 杭锦后旗| 南涧| 丹江口市| 娱乐| 孟州市| 息烽县| 汽车| 马鞍山市| 新津县| 彰化市| 环江| 焦作市| 安阳县| 灵台县| 三江|