简体   繁体   中英

How to remove '.do' prefix from url in Struts1?

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.

  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.

Modify in web.xml and change *.do

<servlet-mapping>
  <servlet-name>myapp</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM