自定义标签3
来源:互联网 发布:飞鱼网络电视手机版 编辑:程序博客网 时间:2024/05/17 09:03
标签案例-开发防盗链标签:
盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有利益的最终用户界面(如广告),直接在自己的网站上向最终用户提供其它服务提供商的服务内容,骗取最终用户的浏览和点击率。受益者不提供资源或提供很少的资源,而真正的服务提供商却得不到任何的收益。
解决途径之一——限制引用页
这种防盗链原理是,服务器获取用户提交信息的网站地址,然后和真正的服务端的地址相比较,如果一致则表明是站内提交,或者为自己信任的站点提交,否则视为盗链。
目标:要开发的标签
<class3g:referer site="http://drinkeye:8080" page="/index.jsp"/>
site:受信任站点,只允许次站点的请求
page:正确的链接页面,发现盗链后将其自动转入此页面
步骤:
1) 标签处理类:
public void doTag() throws JspException, IOException {
PageContext pageContext = (PageContext) this.getJspContext();
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse();
String referer = request.getHeader("referer");
System.out.println(request.getContextPath());
if(referer==null | !referer.startsWith(site)){
//判断是否盗链
//根据page属性值,讲链接重定向指访问被盗链内容的正确页面
String contextPath = request.getContextPath();
if(page.startsWith(contextPath)){
response.sendRedirect(page);
}else if(page.startsWith("/")){
response.sendRedirect(contextPath + page);
}else{
response.sendRedirect(contextPath + "/" + page);
}
throw new SkipPageException();
}
}
2.标签案例-<c:if>标签
标签功能:
<class3g:if exp="${psw==null }">
user == null <br>
</class3g:if>
<%
session.setAttribute("user","Tom");
%>
<class3g:if exp="${user!=null }">
user != null <br>
</class3g:if>
处理类:
public class MyIfTag extends SimpleTagSupport {
private boolean exp;
public void setExp(boolean exp) {
this.exp = exp;
}
public void doTag() throws JspException, IOException {
if(exp){
JspFragment jf = this.getJspBody();
jf.invoke(null);
}
}
}
3、标签案例if else 标签:
<class3g:choose >
<class3g:when exp="${user!=null }">
aaaaaaaaaa
</class3g:when>
<class3g:otherwise>
bbbbbbbbbbbbbbb
</class3g:otherwise>
</class3g:choose>
- 自定义标签<3>标签体
- 自定义标签3
- 自定义标签(3)
- 自定义标签3
- jsp自定义标签-3
- 自定义标签3
- struts1.3自定义标签
- JSP自定义标签(3):带标签体(body)的标签
- 自定义标签(3)带标签体的标签
- 自定义转换器标签(3)
- JSP自定义标签(3)
- jsp学习3-自定义标签
- 冰风3-自定义标签(Demo)
- 自定义标签
- 自定义标签
- 自定义标签
- 自定义标签
- 自定义标签
- 在ubuntu上安装google输入法
- Ubuntu 11.10 安装日志
- 关于解Bug的总结
- linux下usb摄像头采集的YUYV格式转换成JPEG格式的图片
- C#中接口通过基类或派生类对方法的调用
- 自定义标签3
- 使用标准HTML来进行图片上传
- CG快报2011.11.13
- 读写锁的特性
- PHP购物车功能
- 那些过去的 那些在过去中曾经失去的 已经不在我们脑海中漂浮
- HDU 3974
- 计算显示器点距
- 2D和3D图形引擎的混合