servlet2.4規(guī)范
一、(fn函數(shù))
- <c:set var="subStr" value="abcdefghijksdf"
- <c:choose>
- <c:when test="${fn:length(subStr) > 2}">
- <c:out value="${fn:substring(subStr, 0, 2)}......" />
- </c:when>
- <c:otherwise>
- <c:out value="${subStr}" />
- </c:otherwise>
- </c:choose>
注:記得要引用標(biāo)簽庫
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
二、自定義函數(shù)
- package com.uisk.util;
-
-
-
-
- public class UFunction {
-
-
-
-
-
-
-
- public static int getLen(String str) {
- return str.length();
- }
-
-
-
-
-
-
-
-
-
- public static String substr(String str, int start, int end) {
- return str.substring(start, end);
- }
-
-
-
-
-
-
-
-
- public static int chufa(int first, int second) {
- return first / second;
- }
- }
再建一個(gè)tld文件放在WEB-INF目錄下面對其進(jìn)行配置:
- <?xml version="1.0" encoding="UTF-8"?>
- <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
- version="2.0">
- <tlib-version>1.0</tlib-version>
- <short-name>len</short-name>
- <function>
- <description>calculate string length</description><!-- 對這個(gè)EL方法的描述 -->
- <name>getLen</name><!-- 調(diào)用EL方法的名稱 -->
- <function-class>com.cw.common.UFunction</function-class>
- <function-signature>
- int getLen(java.lang.String)
- </function-signature>
- <example>${len:getLen(str)}</example><!-- 例如 -->
- </function>
-
- <function>
- <description>substring</description>
- <name>substr</name>
- <function-class>com.cw.common.UFunction</function-class>
- <function-signature>
- java.lang.String substr(java.lang.String,int,int)
- </function-signature>
- </function>
-
- <function>
- <description>chufa</description>
- <name>chufa</name>
- <function-class>com.cw.common.UFunction</function-class>
- <function-signature>int chufa(int,int)</function-signature>
- </function>
- </taglib>
最后進(jìn)行調(diào)用測試:
- <%@ page language="java" pageEncoding="gbk"%>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <%@ taglib uri="/WEB-INF/mytag.tld" prefix="myTag" %>
-
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <body>
- <c:set var="str" value="自定義函數(shù),做一個(gè)截取字符串長度的測試"></c:set>
- 字條串"${str}"的長度是${myTag:getLen(str)}<br/>
- 字條串"${str}"截取前5個(gè)字符:${myTag:substr(str,0,5)}<br/>
- 5除以3取整數(shù)是:${myTag:chufa(5,3) }
-
- </body>
- </html>
servlet2.3規(guī)范
- <td align=center width='200' id="" nowrap>
- <bean:define id="Myflag" name="para" property="flag" type="java.lang.String" />
- <%
- Myflag = Myflag.substring(0,1);
- System.out.println(Myflag);
- if("0".equals(Myflag)){
- %>待處理<%
- }
- if("1".equals(Myflag)){
- %>處理成功<%
- }
- if("2".equals(Myflag)){
- %>處理失敗<%
- }
- if("3".equals(Myflag)){
- %>未復(fù)核<%
- }
- %>
-
- </td>
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點(diǎn)擊舉報(bào)。