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

查看:175
本文介绍了为什么Java webapps使用.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.

我个人不喜欢延期。

推荐答案

据我所知,这个约定已经由Struts1传播。用户指南如下:

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


5.4.2配置ActionServlet映射



注意:本节中的材料并非特定于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.


有两种常用的方法来定义将要使用的URL是
由控制器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
something)
,映射条目将为
看起来像这样:

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>

以及与
/ logon匹配的请求URI 路径可能是
看起来像这样:

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

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

警告 - 框架无法正常运行如果你为控制器servlet定义了更多
而不是一个< servlet-mapping> 元素

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之后也不会更改URL ,有时候只是因为人们对此感到满意。)

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 webapps使用.do扩展名?它从哪里来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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