Search code examples
javaurlstrutsstruts-1

How to remove '.do' extention from action URL in Struts 1?


I have written a web-application in Struts 1 framework. Everything works fine but on form submission, when user is forwarded to the next page, the URL, which is shown, is actionname.do. I don't want this Struts 1 default suffix on URL. Instead of it I would like to see page's name in URL. How to do it?

Note : I have tried editing servlet mapping in web.xml. Have replaced *.do with / . But In that case even my index page doesn't open.


Solution

    1. Open /WEB-INF/web.xml
    2. You will have to find the servlet-name of the org.apache.struts.action.ActionServlet and the servlet-mapping that corresponds to the servlet-name.

    For example:

    <servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    </servlet>
    
    <servlet-mapping>
      <servlet-name>action</servlet-name>
      <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    

    Finally, simply change the url-pattern to what you desire and redeploy the application.