java - 为什么 Java webapps 使用 .do 扩展名?它从哪里来的?

标签 java servlets web-applications

我一直想知道为什么这么多 Java 开发人员使用“.do”作为其 Web Controller (MVC) 资源的扩展名。示例:http://example.com/register.do

它甚至不像我在 Spring MVC 和 Struts 项目中看到的那样是特定于框架的。 这个“.do”扩展实践从何而来。为什么这样做而不是不扩展? 我觉得我错过了关于这方面的 Java 世界备忘录。

我个人不喜欢扩展。

最佳答案

据我所知,Struts1 已经传播了这种约定。用户指南是这样写的:

5.4.2 Configure the ActionServlet Mapping

Note: The material in this section is not specific to Struts. The configuration of servlet mappings is defined in the Java Servlet Specification. This section describes the most common means of configuring a application.

There are two common approaches to defining the URLs that will be processed by the controller servlet -- prefix matching and extension matching. An appropriate mapping entry for each approach will be described below.

Prefix matching means that you want all URLs that start (after the context path part) with a particular value to be passed to this servlet. Such an entry might look like this:

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

which means that a request URI to match the /logon path described earlier might look like this:

http://www.mycompany.com/myapplication/do/logon

where /myapplication is the context path under which your application is deployed.

Extension mapping, on the other hand, matches request URIs to the action servlet based on the fact that the URI ends with a period followed by a defined set of characters. For example, the JSP processing servlet is mapped to the *.jsp pattern so that it is called to process every JSP page that is requested. To use the *.do extension (which implies "do something"), the mapping entry would look like this:

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

and a request URI to match the /logon path described earlier might look like this:

http://www.mycompany.com/myapplication/logon.do

WARNING - The framework will not operate correctly if you define more than one <servlet-mapping> element for the controller servlet.

WARNING - If you are using the new module support since version 1.1, you should be aware that only extension mapping is supported.

而且我认为这个约定得到了保留(有时 to not change URLs 即使在替换了 Struts1 之后,有时只是因为人们对此感到满意)。

关于java - 为什么 Java webapps 使用 .do 扩展名?它从哪里来的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3597582/

相关文章:

java - 如何在java中传递bash脚本的参数?

java - jsp从servlet读取文件名不可能吗?

php - 如何从头开始设计 Web 应用程序(社区站点)?

java - 我的投票系统已经很好但是

java - 如何使用不同导入的双定时器

Java - 上传到网站 html/js 表单

java - 关于使用 iText 打开 PDF 文件的 Java Servlet 问题

java - tomcat过滤重定向的jsp页面不显示任何内容

.net - 体系结构帮助 : Queries on Subsets

java - Maven是否应该为不同的应用服务器打包不同的WAR?