url rewriting in Struts1
I am developing a web application using Struts1 as web framework. My url pattern in web.x开发者_开发百科ml is:
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
I want to get rid of .do
pattern in urls. So if my url is
http://localhost:38330/MyProject/editFunction.do?function=1
i want it to be like http://localhost:38330/MyProject/editFunction/ . How do I acheive this type of url rewriting ? Thanks for any help
You can use a filter before calling the struts request processor, and this project it's very helpful: http://www.tuckey.org/urlrewrite/
You can map your <url-pattern>
to allow prefix, like
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/action/*</url-pattern>
</servlet-mapping>
Then if you do (e.g.) http://localhost:38330/MyProject/action/editFunction/, your struts action will be called (if mapped correctly on struts-config.xml
).
精彩评论