Servlet3.0 自定义表达式方法
[code="java"] package com.lee.elfunction; public class Functions { //字符串反转 public static String reverse(String text){ return new StringBuffer(text).reverse().toString(); } //统计字符串的个数 public static int countChar(String text){ return text.length(); } } [/code] [code="xml"] 1.0 crazyit http://www.crazyit.org/tags reverse com.lee.elfunction.Functions java.lang.String reverse(java.lang.String) countChar com.lee.elfunction.Functions int countChar(java.lang.String) [/code] [code="java"] <%@page import="java.util.Date"%> <%@page import="java.util.Enumeration"%> <%@page import="java.net.URLDecoder"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page isELIgnored="false"%> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%> <%@ taglib uri="http://www.crazyit.org/tags" prefix="myfun"%> Insert title here <% out.println(request.getParameter("name")); String method=request.getMethod(); if("get".equalsIgnoreCase(method)){ String rawQueryStr=request.getQueryString(); if(rawQueryStr!=null && rawQueryStr.length()>0){ out.println("原始查询字符串为:"+rawQueryStr+"
"); String queryStr=URLDecoder.decode(rawQueryStr,"UTF-8"); out.println("解码后的查询字符串:"+queryStr+"
"); //以& 分割查询字符串 String[]paramPairs=queryStr.split("&"); for(String param:paramPairs){ out.println("每个请求的参数名,值对为:"+param+"
"); String[] nameValue=param.split("="); out.println(nameValue[0]+"参数值是:"+nameValue[1]+"
"); } } }else{ Enumeration headNames=request.getHeaderNames(); while(headNames.hasMoreElements()){ String headname=headNames.nextElement(); out.println(headname+"--->"+request.getHeader(headname)+"
"); } } %>
${a} <% out.println("现在的时间是:"+new Date()); %> 使用自定义表达式函数 ${myfun:reverse(param["name"])} [/code]