當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
html模板(base标签,meta标签,禁用浏览器缓存)+JSP自定义标签荔枝
生活随笔
收集整理的這篇文章主要介紹了
html模板(base标签,meta标签,禁用浏览器缓存)+JSP自定义标签荔枝
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【1】html模板
<html> <head><!-- base標簽表示uri相對路徑的基準路徑 --><base href="http://localhost:8080/asite6/chapter6/ex6_11/visitor.html"/><title>html template</title><!-- meta 模擬響應消息頭:Content-Type 表示內容類型 --> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><!-- meta 模擬響應消息頭:下面3個響應頭都是為了禁用瀏覽器緩存,因為存在著瀏覽器兼容問題所以設置了3個響應頭以覆蓋所有瀏覽器 --><meta http-equiv="Expires" content="0"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Pragma" content="no-cache"> </head> <body><a href="chapter6/ex6_10/validate.jsp">訪問validate.jsp頁面</a> </body> </html> 【2】JSP自定義標簽荔枝1)源碼:
<%@ page contentType="text/html;charset=UTF-8" %> <%@ taglib prefix="tangrong" uri="/validateTag" %> <tangrong:validate/> 如果您看到了這些內容,說明本JSP頁面已經正常執行完畢! <?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>validateTag</short-name><uri>/validateTag</uri><tag><description>validate tag</description><name>validate</name><tag-class>ex6_8.ValidateTag</tag-class><body-content>empty</body-content></tag> </taglib> package ex6_8;import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport;public class ValidateTag extends TagSupport { // 自定義標簽處理器public int doEndTag() throws JspException {HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();String referrer = req.getHeader("referer"); // 訪問請求是從哪個頁面鏈接過來的String sitePart = "http://" + req.getServerName(); // jsp頁面所在服務器地址System.out.println("referrer = " + referrer);System.out.println("sitePart = " + sitePart);if (referrer != null && referrer.startsWith(sitePart)) {return EVAL_PAGE;} else {try {pageContext.getOut().write("對不起,您的訪問方式不合法!");} catch (IOException e) {e.printStackTrace();}return SKIP_PAGE;}} } 2)訪問效果:
總結
以上是生活随笔為你收集整理的html模板(base标签,meta标签,禁用浏览器缓存)+JSP自定义标签荔枝的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 世家公子是什么意思 世家公子是指什么
- 下一篇: 转】Eclipse编辑Spring配置文