Servlet3.0カスタム式メソッド

4180 ワード


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();
	}
	
}

<?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/j2eeweb-jsptaglibrary_2_0.xsd"
      version="2.0">
	<tlib-version>1.0</tlib-version>
	<short-name>crazyit</short-name>
	<uri>http://www.crazyit.org/tags</uri>
	<function>
		<name>reverse</name>
		<function-class>com.lee.elfunction.Functions</function-class>
		<function-signature>
			java.lang.String reverse(java.lang.String)
		</function-signature>
	</function>
	
	<function>
		<name>countChar</name>
		<function-class>com.lee.elfunction.Functions</function-class>
		<function-signature>
			int countChar(java.lang.String)
		</function-signature>
	</function>
</taglib>


<%@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"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<%
	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+"<br/>");
			String queryStr=URLDecoder.decode(rawQueryStr,"UTF-8");
			out.println(" :"+queryStr+"<br/>");
			
			// &  
			String[]paramPairs=queryStr.split("&");
			for(String param:paramPairs){
				out.println(" , :"+param+"<br/>");
				String[] nameValue=param.split("=");
				out.println(nameValue[0]+" :"+nameValue[1]+"<br/>");
			}
		}
	}else{
		Enumeration<String> headNames=request.getHeaderNames();
		while(headNames.hasMoreElements()){
			String headname=headNames.nextElement();
			out.println(headname+"--->"+request.getHeader(headname)+"<br/>");
		}
	}
%>
<body>
<form action="getPostParam.jsp" method="post">
	<input name="name"/>
	<input name="age"/>
	<input type="submit" value=" "/>
</form>
<c:set var="a" value="1"/>
<c:forEach  begin="0" end="3">         
    <c:set var="a" value="${a+1}"/>
</c:forEach> 
${a}

<%
	out.println(" :"+new Date());

%>
 
${myfun:reverse(param["name"])}
</body>
</html>