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实现上传() ,所以,我又进行了一下修改,就一句,内容如下:

<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="https://www.linuxidc.com/Software_Site/article?article.atcID=${cpsnews.atcID}">XXX</a>改成<a href="https://www.linuxidc.com/Software_Site/${cpsnews.atcID}.shtml">XXX</a>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/aacbf004caa9509f802a85f41a500af9.html