Java 什么是 servlet 的“显示名称”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3805262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 05:16:10  来源:igfitidea点击:

What is a servlet's "display-name" for?

javaservletsweb.xml

提问by Matt Ball

The <display-name>element appears to be a valid sub-element of the <servlet>element as per the Servlet 2.5 deployment descriptor XSD. That is, according to Eclipse's XML validator, this:

所述<display-name>元件似乎是一个有效的子元素<servlet>元素作为每个所述的Servlet 2.5部署描述符XSD。也就是说,根据 Eclipse 的 XML 验证器,这是:

<servlet>
    <servlet-name>FooServlet</servlet-name>
    <display-name>FooServlet</display-name>
    <servlet-class>com.bar.servlet.FooServlet</servlet-class>
</servlet>

is a valid servlet-mapping, while this:

是有效的servlet-mapping,而这个:

<servlet>
    <servlet-name>FooServlet</servlet-name>
    <random-tag-name>OMGWTFBBQ</random-tag-name>
    <servlet-class>com.bar.servlet.FooServlet</servlet-class>
</servlet>

is not (which seems reasonable enough).

不是(这似乎足够合理)。

What's the display-nameactually used for? I haven't been able to dig up anything informative on it.

有什么display-name实际用途?我一直无法挖掘出任何有关它的信息。

采纳答案by skaffman

The <servlet-name>is the canonical, internal name of the servlet, and is used as the key linking things like url-patterns to servlets. <display-name>is for use by admin tools and the like.

<servlet-name>是servlet的规范,内部名称,并且被用作键连接之类的网址,图案的servlet。<display-name>供管理工具等使用。

This perhaps makes more sense when you consider that the XML Schema permits multiple <display-name>elements, for various languages, e.g.

当您考虑到 XML Schema 允许<display-name>针对各种语言的多个元素时,这可能更有意义,例如

<servlet>
    <servlet-name>MyServlet</servlet-name>
    <displayable-name xml:lang="en">My Servlet</displayable-name>
    <displayable-name xml:lang="fr">Ma Servlet</displayable-name>
</servlet>

(pardon my Frenglais)

(原谅我的弗朗格莱)

回答by bosmacs

I believe it's used primarily by J2EE web-management consoles, when displaying statistics, etc.

我相信它主要由 J2EE Web 管理控制台在显示统计信息等时使用。

回答by Nate

The servlet-nameis used to refer to the servlet in other tags (like servlet-mapping). This could be thought of as the "internal name" of the servlet. The display-nameis the "external name" of the servlet - it's what should show up on a management consoles of servlet containers. Usually, web apps are managed as a unit - they are deployed/undeployed/restarted/etc. as a whole, not managing individual servlets - so there's not a place where you would usually see this display name used.

servlet-name被用于指代在其他标记(例如小服务程序servlet-mapping)。这可以被认为是 servlet 的“内部名称”。这display-name是 servlet 的“外部名称”——它应该显示在 servlet 容器的管理控制台上。通常,Web 应用程序作为一个单元进行管理 - 它们被部署/取消部署/重新启动等。作为一个整体,不管理单个 servlet - 因此通常不会在某个地方看到使用此显示名称。

回答by IqbalHamid

The <display-name>element is a child element of <servlet>. These are elements used within web.xml deployment descriptor files. The <display-name>is optional and allows for a short name to be associated with the servlet which can be potentially read by GUI tools (such as a web browser) to literally display the name of the servlet to the client if that is required. However, in practice, it is almost never used so can be safely disregarded.

<display-name>元素是 的子元素<servlet>。这些是在 web.xml 部署描述符文件中使用的元素。这 <display-name>是可选的,并允许与 servlet 相关联的短名称,GUI 工具(例如 Web 浏览器)可能会读取该短名称,以便在需要时向客户端逐字显示 servlet 的名称。然而,在实践中,它几乎从未使用过,因此可以安全地忽略。