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

你可能感兴趣的:(struts2,伪静态化)