Java 你如何在 web.xml 的 <web-app> 标签中指定根上下文?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/664059/
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
How do you specify the root context in your <web-app> tags in web.xml?
提问by sewardrobert
I would like to specify the root context of my Java web application in my WAR file. How can I do this using valid web-app
XML in a web.xml
file?
我想在我的 WAR 文件中指定我的 Java Web 应用程序的根上下文。如何使用文件中的有效web-app
XML执行此web.xml
操作?
Oh, yes I would like to do this in an application server agnostic way.
哦,是的,我想以与应用程序服务器无关的方式执行此操作。
回答by cletus
This can't be done in an appserver agnostic way. Context root isn't part of the standard web.xml file. It's either specified when you deploy the app or in an appserver specific descriptor.
这不能以与应用程序服务器无关的方式完成。上下文根不是标准 web.xml 文件的一部分。它要么在您部署应用程序时指定,要么在特定于应用程序服务器的描述符中指定。
- Glassfish: sun-web.xml;
- JBoss: jboss-web.xml;
- Weblogic: weblogic.xml;
- Tomcat: context.xml;
- WebSphere: ibm-web-ext.xml.
- Glassfish: sun-web.xml;
- JBoss: jboss-web.xml;
- 网络逻辑:weblogic.xml;
- Tomcat:context.xml;
- WebSphere:ibm-web-ext.xml。
Note:the above applies to deploying WAR files. EAR files are a different story and the context can be specified as part of the application.xml deployment descriptor.
注意:以上适用于部署 WAR 文件。EAR 文件是另一回事,可以将上下文指定为application.xml 部署描述符的一部分。
回答by Perky
You can use like this in web.xml.
您可以在 web.xml 中像这样使用。
<env-entry>
<description>web app</description>
<env-entry-name>appCxtRoot</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>webapp-@context-root-value@</env-entry-value>
</env-entry>