日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

页面伪静态化 java_UrlRewrite 伪静态化页面

發布時間:2024/9/27 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 页面伪静态化 java_UrlRewrite 伪静态化页面 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

官網

http://tuckey.org/urlrewrite/#download

概念

UrlRewrite 地址重寫,可以將非靜態頁面地址進行轉換,偽裝成html后綴的網頁。

優點

提高安全性,可以有效的避免一些參數名、ID等完全暴露在用戶面前,如果用戶隨便亂輸的話,不符合規則的話直接會返回個404或錯誤頁面,這比直接返回500或一大堆服務器錯誤信息要好的多;

美化URL,去除了那些比如*.do之類的后綴名、長長的參數串等,可以自己組織精簡更能反映訪問模塊內容的URL;

更有利于搜索引擎的收入,通過對URL的一些優化,可以使搜索引擎更好的識別與收錄網站的信息;

轉換規則

rule說明

通過正則表達式對請求進行匹配

實際請求地址

^/m/category_([0-9]+)/content_([0-9]+).html$

/main.jsp?categoryid=$1&contentid=$2

outbound-rule說明

頁面顯示的鏈接規則表達式

轉換為實際顯示的地址

^/main.jsp\?categoryid=([0-9]+)&contentid=([0-9]+)$

/m/category_$1/content_$2.html

rule與outbound-rule需要匹配。

注意轉義字符:

& 轉義為 &

? 轉義為 /?

示例代碼

1.下載項目jar包并加載到項目工程中。

2.將urlrewrite.xml文件加載到WEB-INF目錄下,并編寫轉換規則,編寫規則使用正則表達式。

示例代碼

/p>

"http://tuckey.org/res/dtds/urlrewrite3.1.dtd">

^/index.html$

/index.jsp

^/login.html$

/login2.jsp

^/query.html$

/queryResult.jsp

^/m/category_([0-9]+).html$

/main.jsp?categoryid=$1

^/m/category_([0-9]+)/content_([0-9]+).html$

/main.jsp?categoryid=$1&contentid=$2

^/v/category_([0-9]+)/content_([0-9]+).html$

/view.jsp?categoryid=$1&contentid=$2

^/f/category_([0-9]+)/pageNow_([0-9]+).html$

/frame.jsp?categoryid=$1&pageNow=$2

^/p/category_([0-9]+)/pageNow_([0-9]+).html$

/proframe.jsp?categoryid=$1&pageNow=$2

^/c/category_([0-9]+)/pageNow_([0-9]+).html$

/credentails.jsp?categoryid=$1&pageNow=$2

^/p/depart_([0-9]+).html$

/people.jsp?departid=$1

^/index.jsp

/index.html

^/login2.jsp

/login.html

^/queryResult.jsp

/query.html

^/main.jsp\?categoryid=([0-9]+)$

/m/category_$1.html

^/main.jsp\?categoryid=([0-9]+)&contentid=([0-9]+)$

/m/category_$1/content_$2.html

^/view.jsp\?categoryid=([0-9]+)&contentid=([0-9]+)$

/v/category_$1/content_$2.html

^/frame.jsp\?categoryid=([0-9]+)&pageNow=([0-9]+)$

/f/category_$1/pageNow_$2.html

^/proframe.jsp\?categoryid=([0-9]+)&pageNow=([0-9]+)$

/p/category_$1/pageNow_$2.html

^/credentails.jsp\?categoryid=([0-9]+)&pageNow=([0-9]+)$

/c/category_$1/pageNow_$2.html

^/people.jsp\?departid=([0-9]+)$

/p/depart_$1.html

3.在web.xml文件中進行聲名。

UrlRewriteFilter

org.tuckey.web.filters.urlrewrite.UrlRewriteFilter

UrlRewriteFilter

/*

REQUEST

FORWARD

4.Jsp頁面鏈接聲名方式

">測試

說明:按照API的指引,java里面編寫的鏈接應該使用轉義字符 & 代替 & 才對,但是我使用了&反而不起作用,使用&才行,所以需要大家多測試一下,而且我在本機上部署訪問,顯示的鏈接規則是不生效的(即:無法顯示 /m/category_1/content_2.html ),但是可以通過這樣的規則去正常訪問,反而部署在服務器上就正常顯示。

測試結果

訪問http://xxx.com/index.html 實際訪問到的是index.jsp頁面

參考案例

http://pihai.iteye.com/blog/384386

http://blog.sina.com.cn/s/blog_7a2356a60100x4fy.html

http://blog.sina.com.cn/s/blog_a72be0600101dwxl.html

總結

以上是生活随笔為你收集整理的页面伪静态化 java_UrlRewrite 伪静态化页面的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。