国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

jstl自定義標簽防盜鏈

2019-11-09 13:48:06
字體:
來源:轉載
供稿:網友

jstl自定義標簽防盜鏈

*自定義標簽的使用主要包括以下三個部分1.tagServlet代碼設計2.tld文件配置3.jsp頁面引用自定義標簽

代碼塊

tagServlet代碼如下:

@requires_authorizationpackage example;import java.io.IOException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.jsp.JspException;import javax.servlet.jsp.PageContext;import javax.servlet.jsp.SkipPageException;import javax.servlet.jsp.tagext.SimpleTagSupport;public class tagFangDaoLian extends SimpleTagSupport{ PRivate String site; private String page; public void setSite(String site) { this.site = site; } public void setPage(String page) { this.page = page; } @Override public void doTag() throws JspException, IOException { PageContext pc = (PageContext) this.getJspContext(); HttpServletRequest request = (HttpServletRequest) pc.getRequest(); String referer = request.getHeader("referer"); HttpServletResponse response = (HttpServletResponse) pc.getResponse(); System.out.println(request.getContextPath()); if(referer==null||!referer.startsWith(site)){ //做出判斷,如果為空或符合盜鏈鏈接,準備進入盜鏈者界面 if(page.startsWith(request.getContextPath())){ response.sendRedirect(page); }else if(page.startsWith("/")){ response.sendRedirect(request.getContextPath()+page); }else{ response.sendRedirect(request.getContextPath()+"/"+page); } throw new SkipPageException(); } }}

tld配置文件代碼如下:

@requires_authorization<?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"> <tlib-version>1.0</tlib-version> <short-name>showlist</short-name> <uri>/tag</uri><tag> <name>untheft</name> <tag-class>example.tagFangDaoLian</tag-class> <body-content>empty</body-content> <attribute> <name>site</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>page</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute></tag></taglib>

jsp頁面調用如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib prefix="m" uri="/tag" %>** <m:untheft site="http://localhost" page="untheft.jsp"/>** <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'main.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keyWords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/CSS" href="styles.css"> --> </head> <body> <h3>選項</h3> <a href="jsp/save.jsp">添加新員工</a> <a href="${pageContext.request.contextPath}/servlet/selectPageServlet?pageNum=1">查看所有員工</a> </body></html>

說明:

當用戶以http:localhost(即site,可以自己更改屬性)為請求頭時,標簽將執行,自動轉入page界面[^footnote].


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东海县| 桂平市| 盐津县| 石嘴山市| 灵石县| 剑河县| 都安| 克东县| 正蓝旗| 平原县| 金山区| 毕节市| 托克托县| 电白县| 都安| 孟连| 池州市| 陆河县| 定日县| 岳池县| 达州市| 习水县| 墨竹工卡县| 兰考县| 蒙自县| 永清县| 正定县| 阳西县| 宁城县| 金昌市| 铁力市| 田阳县| 科技| 文成县| 雅江县| 瑞丽市| 瑞安市| 岳普湖县| 海原县| 溧水县| 虞城县|