context.xml vs web.xml in web application

纵饮孤独 提交于 2019-12-18 13:27:17

问题


I am developing a small web application application. The objective is to create one welcome index.html page with Ajax + one servlet to handle ajax requests.

Although I thought I would be fine with a web.xml only, I don't want to deploy to /, but to /MyApp. NetBeans's project properties offers options to set a context path, which helps me deploying to /MyApp. However, it automatically adds a /META-INF/context.xml file, which is a bit confusing.

My questions are:

1) Do I really need a context.xml file do deploy to /MyApp instead of /?

2) If answer to 1) is no, how to accomplish the same with web.xml only?

3) What is exactly context.xml to web.xml?


回答1:


/META-INF/context.xml is a Tomcat-specific config file. It's used to configure how your app is deployed to Tomcat, including, among other things, the context path at which it exists. Other containers have similar files that can be included in a WAR for container configuration. To answer your questions:

  1. No. The embedded context.xml is only one way to set the context path, and as I indicated, it'll only work in Tomcat. In Tomcat, default behavior is to deploy webapps to a context that has the name of the war file, without the ".war" extension.
  2. You can't set a context path in web.xml. That's your application's deployment descriptor. It configures your application, and the context path is external to your app. It belongs to the server/container you're deploying the app to. Configuring a context path is always done in the container's configuration.
  3. If by "config.xml", you meant "context.xml", then I think I've already answered that. If not, clarify your question.


来源:https://stackoverflow.com/questions/7761647/context-xml-vs-web-xml-in-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!