June Rajkhowa
June Rajkhowa

Reputation: 11

url rewriting in Struts1

I am developing a web application using Struts1 as web framework. My url pattern in web.xml 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

Upvotes: 1

Views: 1325

Answers (2)

Buhake Sindi
Buhake Sindi

Reputation: 89209

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).

Upvotes: 0

Miguel Prz
Miguel Prz

Reputation: 13792

You can use a filter before calling the struts request processor, and this project it's very helpful: http://www.tuckey.org/urlrewrite/

Upvotes: 1

Related Questions