public class MyReferer extends BodyTagSupport {
private String site;
private String back;
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
public String getBack() {
return back;
}
public void setBack(String back) {
this.back = back;
}
public int doEndTag() throws JspException {
// 获取JSP上下文环境对象
PageContext pageContext = this.pageContext;
// 获取到request对象
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
// 判断
String header = request.getHeader("referer");
if(header != null && header.startsWith(getSite())){
// 执行后续的页面
return Tag.EVAL_PAGE;
}else{
// 页面的重定向
HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
try {
response.sendRedirect(getBack());
} catch (IOException e) {
e.printStackTrace();
}
// 不执行
return Tag.SKIP_PAGE;
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<!-- 2. 编写标签库描述文件 -->
<tlib-version>1.0</tlib-version>
<short-name>jnb</short-name>
<tag>
<name>referer</name>
<tag-class>cn.itcast.custom.MyReferer</tag-class>
<body-content>empty</body-content>
<attribute>
<name>site</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>back</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
<%@taglib uri="/WEB-INF/referer.tld" prefix="my"%> <my:referer site=http://localhost:8080/day11/list.jsp back="/day11/list.jsp"/>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:choose>
<c:when test="<%= 12>1 %>">
大于
</c:when>
<c:otherwise>
小于
</c:otherwise>
</c:choose>
public class ChooseTag extends SimpleTagSupport {
private boolean tag = true;
public boolean isTag() {
return tag;
}
public void setTag(boolean tag) {
this.tag = tag;
}
// 遇到标签自动执行
public void doTag() throws JspException, IOException {
// 获取标签体对象
JspFragment body = this.getJspBody();
// 执行标签体
body.invoke(null);
super.doTag();
}
}
public class WhenTag extends SimpleTagSupport {
private boolean test;
public boolean isTest() {
return test;
}
public void setTest(boolean test) {
this.test = test;
}
// 遇到标签自动执行
public void doTag() throws JspException, IOException {
// 获取父元素
ChooseTag choose = (ChooseTag)this.getParent();
// 获取父元素的标记变量值
boolean parent = choose.isTag();
// 判断
if( parent && this.isTest() ){
// 执行标签体
JspFragment body = this.getJspBody();
body.invoke(null);
}
super.doTag();
}
}
public class OtherwiseTag extends SimpleTagSupport {
// 遇到标签自动执行
public void doTag() throws JspException, IOException {
// 获取父元素
ChooseTag choose = (ChooseTag)this.getParent();
// 获取父元素的标记变量值
boolean parent = choose.isTag();
// 判断
if(parent){
// 执行标签体
JspFragment body = this.getJspBody();
body.invoke(null);
}
super.doTag();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<!-- 2. 编写标签库描述文件 -->
<tlib-version>1.0</tlib-version>
<short-name>jnb</short-name>
<tag>
<name>choose</name>
<tag-class>cn.itcast.tags.ChooseTag</tag-class>
<body-content>scriptless</body-content> JSP2.0方式
</tag>
<tag>
<name>when</name>
<tag-class>cn.itcast.tags.WhenTag</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>test</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>otherwise</name>
<tag-class>cn.itcast.tags.OtherwiseTag</tag-class>
<body-content>scriptless</body-content>
</tag>
</taglib>
<%@taglib uri="/WEB-INF/ifelse.tld" prefix="jnb"%>
<jnb:choose>
<jnb:when test="<%= 1>2 %>">
小于
</jnb:when>
<jnb:otherwise>
大于
</jnb:otherwise>
</jnb:choose>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有