Java --- 自定义EL函数

一、创建UserDefinedELFunction类,用于处理函数业务

 

public class UserDefinedELFunction {
	public static String toUpperCase(String s){
		return s.toUpperCase();
	}
}

 

 

 

二、在WEB-INF下创建userDefinedELFunction.tld文件



	
	1.0
	
	elf
	
	http://www.xxx.com/jsp/functions
	
		toUpperCase
		com.xxx.functions.UserDefinedELFunction
		
		java.lang.String toUpperCase( java.lang.String )
	

	1.0
	
	elf
	
	http://www.xxx.com/jsp/functions
	
		toUpperCase
		com.xxx.functions.UserDefinedELFunction
		
		java.lang.String toUpperCase( java.lang.String )
	

 

 

三、在web.xml中配置taglib,可省略



  
    index.jsp
  
  


  	
  		http://www.xxx.com/jsp/functions
  		/WEB-INF/userDefinedELFunction.tld
  	
  
   -->


 

 

四、在JSP中映入taglib

<%@ page import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.xxx.com/jsp/functions" prefix="elf"%>

  
	自定义EL函数  
  
  
  
    <%
    	pageContext.setAttribute("s", "abcdefg");
     %>
     ${s}
${elf:toUpperCase(s)}
<%@ taglib uri="http://www.xxx.com/jsp/functions" prefix="elf"%> 自定义EL函数 <% pageContext.setAttribute("s", "abcdefg"); %> ${s}
${elf:toUpperCase(s)}

 

 

你可能感兴趣的:(Java)