In the Jstl package, Url:http://java.sun.com/jsp/jstl/functions is a self-contained El function library, and if that doesn't meet your needs, you can write your own custom El function yourself.
Write an escaped El function 1th step, write aStatic MethodsJava class (El can only call static methods)
//http Escape Code
Public class HTTPFilter
{
Public static String Filter (Stringmessage)
{
if (Message = =null)
return (null);
char content[] =new char[Message.length ()];
Message.getchars (0,message.length (), content, 0);
Stringbufferresult = newstringbuffer (content. Length + 50);
for (int i = 0; i < content.) length; i++)
{
Switch (Content[i])
{
Case ' < ':
Result.append ("<");
break;
Case ' > ':
Result.append (">");
break;
Case ' & ':
Result.append ("&");
break;
Case ' "':
Result.append (""");
break;
default:
Result.append (Content[i]);
}
}
return (Result.tostring ());
}
}
2nd step, in web-
inf\ directory to create a new
TLDFile Zhong.tld, describing the function
<? 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/j2eehttp://java.sun.com/xml/ns/j2ee/ Web-jsptaglibrary_2_0.xsd "
version="2.0">
< Description > Custom E-functions </description>
< tlib-version >1.0</tlib-version>
< Short-name > Simpletaglibrary</short-name>
< URI >/zhong</uri>
< function >
< name >filter</name>
< Function-class >cn.zhong.web.el.HttpFilter</function-class>
< function-signature >java.lang.String Filter (java.lang.String)</function-signature> <!-- return value parameter type --
<!--<function-signature>java.lang.string Filter (java.lang.String,int[],java.lang.string[], Java.untils.List) </function-signature>-->
</ function >
</ taglib >
3rd step, use on JSP page
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@tagliburi= "/web-inf/itcast.tld" prefix= "Myfn"%>
<! DOCTYPE HTML Public "-//w3c//dtd HTML4.01 transitional//en" >
<title> Custom El function Testing </title>
<body>
${myfn:filter ("<a href= ' > Dot </a>")}
</body>
Custom El Functions