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

本小妞迷上赌 提交于 2020-01-11 09:51:58

问题


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>


来源:https://stackoverflow.com/questions/25032331/how-to-remove-do-prefix-from-url-in-struts1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!