简体   繁体   English

如何从Struts1中的url中删除'.do'前缀?

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

I have written a web-application in Struts 1 framework. 我在Struts 1框架中编写了一个Web应用程序。 Everything works fine but on form submission when user is forwarded to next page URL which is shown is actionname.do . 一切正常,但在表单提交时,用户被转发到下一页URL,显示的是actionname.do I don't want this Struts 1 default suffix on URL. 我不希望这个Struts 1在URL上有默认后缀。 Instead of it I would like to see page's name in URL. 而不是它我想在URL中看到页面的名称。 How to do it? 怎么做?

Note : I have tried editing servlet mapping in web.xml . 注意:我已经尝试在web.xml编辑servlet映射。 Have replaced /*.do . 已更换/*.do But In that case even my index page doesn't open. 但在这种情况下,即使我的索引页面也无法打开。

  1. Open /WEB-INF/web.xml 打开/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 . 您必须找到org.apache.struts.action.ActionServletservlet-name和与servlet-name对应的servlet-mapping

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. 最后,只需将url-pattern更改为您想要的并重新部署应用程序。

Modify in web.xml and change *.do web.xml修改并更改*.do

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

In your web.xml, replace url pattern *.do with / 在你的web.xml中,用/替换url pattern *.do

<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 /* 然后使用Tuckey URL重写器规则将其更改为/*

<rule>
  <from>^/(\w+)*/$</from>
  <to>/c/$1</to>
</rule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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