Context.xml vs web.xml in web application

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

Although I thought everything would be alright with web.xml , I don't want to deploy it to / , but to /MyApp . The properties of the NetBeans project offer options for setting the path to the context that helps me get into /MyApp . However, it automatically adds the file /META-INF/context.xml , which is a bit confusing.

My questions:

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

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

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

+6
source share
1 answer

/META-INF/context.xml is a configuration file specific to Tomcat . It was used to configure the deployment of your application on Tomcat, including, among other things, the context path in which it exists. Other containers have similar files that can be included in the WAR configuration for containers. To answer your questions:

  • Not. The built-in context.xml is only one way to set the context path, and as I pointed out, it will only work on Tomcat. In Tomcat, the default behavior is to deploy webapps in a context that has the name of a war file without a .war extension.
  • You cannot set the context path in web.xml. This is the deployment descriptor of your application. It configures your application, and the context path is external to your application. It belongs to the server / container to which the application is being deployed. Context path configuration is always performed in the container configuration.
  • If "config.xml", you mean "context.xml", then I think I already answered that. If not, ask your question.
+9
source

Source: https://habr.com/ru/post/899261/


All Articles