为什么 Java 网络应用程序使用 .do 扩展名?它从哪里来的? [英] Why do Java webapps use .do extension? Where did it come from?

查看:22
本文介绍了为什么 Java 网络应用程序使用 .do 扩展名?它从哪里来的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have always wondered why so many Java developers use ".do" as the extension for their web controller (MVC) resources. Example: http://example.com/register.do

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

It doesn't even seem to be framework specific as I have seen it in Spring MVC and Struts projects. Where did this ".do" extension practice come from. Why was this done instead of no extension? I feel like I missed the Java world memo on this.

就我个人而言,我更喜欢不扩展.

Personally I prefer no extension.

推荐答案

据我所知,这个约定已经由 Struts1 传播.用户指南是这样写的:

To my knowledge, this convention has been spread by Struts1. The user guide puts it like this:

注意: 本节中的材料并非特定于 Struts.这servlet 映射的配置是在 Java Servlet 中定义规格.本节描述最常见的配置方式申请.

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.

有两种常见的方法定义 URLs由控制器 servlet 处理——前缀匹配和扩展匹配.适当的映射条目将描述每种方法下面.

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.

前缀匹配意味着你想要所有开始的 URL(在上下文之后路径部分)具有特定值传递给这个servlet.这样一个条目可能如下所示:

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>

这意味着请求 URI匹配描述的 /logon 路径之前可能看起来像这样:

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

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

其中 /myapplication 是上下文您的应用程序所在的路径部署.

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

另一方面,扩展映射,将请求 URI 与操作匹配servlet 基于 URI 的事实以句号结尾,后跟定义的字符集.为了例如,JSP 处理 servlet 是映射到 *.jsp 模式,以便调用它来处理每个 JSP 页面这是要求的.使用*.do扩展(这意味着做东西"),映射条目将看起来像这样:

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>

和一个请求 URI 来匹配前面描述的 /logon 路径可能看起来像这样:

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

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

警告 - 如果您定义更多,框架将无法正常运行不止一个 元素用于控制器 servlet.

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

警告 - 如果您使用自 1.1 版以来的新模块支持,您应该知道只有扩展支持映射.

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

而且我认为这个约定一直被保留(有时不改变网址即使在替换了 Struts1 之后,有时只是因为人们对它感到满意).

And I think this convention has been kept (sometimes to not change URLs even after replacing Struts1, sometimes just because people were happy with it).

这篇关于为什么 Java 网络应用程序使用 .do 扩展名?它从哪里来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆