package com.bjpowernode.simpletag;
public class LoopTagBody extends SimpleTagSupport {
private int count; //定义一个属性,用来指定循环次数
public void setCount(int count) { //为该属性设置setter方法
this.count = count;
}
@Override
public void doTag() throws JspException, IOException {
JspFragment fragment = this.getJspBody();
for(int i=0;i<this.count;i++) { //使用属性就可以指定循环次数
fragment.invoke(null);
}
}
}
<?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/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>A tag library exercising SimpleTag handlers.</description>
<tlib-version>1.0</tlib-version>
<short-name>SimpleTagLibrary</short-name>
<uri>simpletag</uri>
<tag>
<name>loopbody</name>
<tag-class>com.bjpowernode.simpletag.LoopTagBody</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>count</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
<%@ taglib uri="simpletag" prefix="simple" %>
<simple:loopbody count="5">
神乐! <br>
</simple:loopbody>
package com.bjpowernode.simpletag;
public class DateAttributeTag extends SimpleTagSupport {
private Date date;
public void setDate(Date date) {
this.date = date;
}
@Override
public void doTag() throws JspException, IOException {
this.getJspContext().getOut().write(date.toString());
}
}
<tag>
<name>showtime</name> <tag-class>com.bjpowernode.simpletag.DateAttributeTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>date</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<simple:showtime date="<%=new Date() %>"/>
package com.bjpowernode.simpletag;
public class RefererTag extends SimpleTagSupport {
private String site; //指定允许来访请求的网址
private String location; //若非指定来访请求的网址应该先跳转到哪里去
public void setSite(String site) {
this.site = site;
}
public void setLocation(String location) {
this.location = location;
}
@Override
public void doTag() throws JspException, IOException {
PageContext pageContext = (PageContext) this.getJspContext();
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
String requestUrl = request.getHeader("referer");
if(requestUrl==null || !requestUrl.startsWith(site)) {
response.sendRedirect(request.getContextPath()+this.location);
throw new SkipPageException();
}
}
}
<tag>
<name>referer</name>
<tag-class>com.bjpowernode.simpletag.RefererTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>site</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>location</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<simple:referer site="http://www.bjpowernode.com" location="/index.jsp" /> <!DOCTYPE HTML> <html> <head> <title>My JSP 'simpletagdemo.jsp' starting page</title> </head> 。。。 </html>
package com.bjpowernode.simpletag;
public class HtmlFilterTag extends SimpleTagSupport {
@Override
public void doTag() throws JspException, IOException {
JspFragment fragment = this.getJspBody();
StringWriter writer = new StringWriter();
fragment.invoke(writer);
StringBuffer buffer = writer.getBuffer();
String content = filter(buffer.toString());
this.getJspContext().getOut().write(content);
}
public String filter(String message) {
if (message == null)
return (null);
char content[] = new char[message.length()];
message.getChars(0, message.length(), content, 0);
StringBuilder result = new StringBuilder(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());
}
}
<tag>
<name>filterhtml</name>
<tag-class>com.bjpowernode.simpletag.HtmlFilterTag</tag-class>
<body-content>scriptless</body-content>
</tag>
<simple:filterhtml>
<a href="www.baidu.com" rel="external nofollow" >百度</a>
</simple:filterhtml>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有