-->

How to remove '.do' prefix from url in Str

2020-04-11 18:15发布

问题:

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:

  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.



回答2:

Modify in web.xml and change *.do

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


回答3:

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>


回答4:

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>