歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

struts2下如何實現偽靜態

最近想在項目中使用偽靜態技術,項目使用的是struts2框架,通過網上的搜集總結,我這裡自己總結出一套自己的方案:
 
1、在web.xml文件中修改如下:

        <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
 </filter-mapping>
 
 <filter>
  <filter-name>UrlRewriteFilter</filter-name>
  <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>UrlRewriteFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

2、在WEB-INF文件下新建urlrewrite.xml文件,內容如下:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">

<urlrewrite>
 <rule>
  <from>/([0-9]+).shtml$</from>
  <to type="forward">article?article.atcID=$1</to>
 </rule>
</urlrewrite>

ok,這樣就可以了,不過我的項目 struts2整合CKEditor和CKFinder實現上傳(http://www.linuxidc.com/Linux/2013-04/82957.htm) ,所以,我又進行了一下修改,就一句,內容如下:

 <filter>
  <filter-name>struts2</filter-name>
  <!-- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> -->
  <filter-class>cn.edu.csu.software.filters.FCKFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
 </filter-mapping>
 
 <filter>
  <filter-name>UrlRewriteFilter</filter-name>
  <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>UrlRewriteFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

FCKFilter如果各位不理解,可以看看struts2整合CKEditor和CKFinder實現上傳這篇文章。

3、然後,將jsp中這樣的代碼修改一下<a href="/Software_Site/article?article.atcID=${cpsnews.atcID}">XXX</a>改成<a href="/Software_Site/${cpsnews.atcID}.shtml">XXX</a>

Copyright © Linux教程網 All Rights Reserved