标签:
在jstl包中,url:http://java.sun.com/jsp/jstl/functions是自带的el函数库,如果这些不能满足你的需要,就可以自己动手编写自定义的el函数。
//http转义代码
public classHttpFilter
{
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());
}
}
<?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>自定义的e函数</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><!-- 返回值 参数类型 -->
<!-- <function-signature>java.lang.String filter(java.lang.String,int[],java.lang.String[],java.untils.List)</function-signature>-->
</function>
</taglib>
<%@ 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">
<html>
<head>
<title>自定义el函数测试</title>
</head>
<body>
${myfn:filter("<a href=‘‘>点点</a>")}
</body>
</html>
标签:
原文地址:http://blog.csdn.net/u014352836/article/details/46634049