3

I have written a web-application in Struts 1 framework. Everything works fine but on form submission when user is forwarded to next page 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 . But In that case even my index page doesn't open.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Abhijeet Panwar
  • 1,837
  • 3
  • 26
  • 48

4 Answers4

4

In your web.xml, replace url pattern *.do with /

<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>/</url-pattern>
</servlet-mapping>
Wundwin Born
  • 3,467
  • 19
  • 37
  • This removed .do from url but I want to display that page name, On which user is forwarded.In this case it show actioname in url – Abhijeet Panwar Jul 30 '14 at 09:04
2
  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.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
2

Modify in web.xml and change *.do

<servlet-mapping>
  <servlet-name>myapp</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>
Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
1

You can use this mapping

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>/c/*</url-pattern>
</servlet-mapping>

Then use Tuckey URL rewriter rule to change this to /*

<rule>
  <from>^/(\w+)*/$</from>
  <to>/c/$1</to>
</rule>
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • It seems that it will work for me, but I have a question that this will be configured in a filter, right? So url will be changed to home.jsp(I am considering that next page is login.jsp which should be open) as soon as if control goes to action class.What if an error has occurred and next page which will be open will be showerror.jsp? As It will show home.jsp – Abhijeet Panwar Jul 30 '14 at 11:41
  • It's unclear what you asking, could you post `struts-config.xml`? – Roman C Jul 30 '14 at 21:06