简体   繁体   中英

What is the purpose of the web.xml file in a Java EE server using Spring?

I am new to spring and i want to know the concepts regarding Spring.I am working on a spring project having a web.xml file as follows:

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.vxml</url-pattern>
</servlet-mapping>


<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

I want to know that what does this web.xml do? please help me...

It isn't really productive to ask questions in a forum for which the answer fills whole chapters of books. I would advise you to read through the free online book http://pdf.coreservlets.com , which in my opinion is one of the best books on Servlets out there. Its old and so it is missing some information, but still a very good resource to help you understand what it all means.

The short answer is: the web.xml is used to configure certain aspects of your web application. In the last servlet specification (3.0) it has become mostly obsolete. You can still use it, but for most things (like servlets) you can just use annotations nowadays.

If you're working with a container that doesn't support the Servlet 3.0 specification you're still obligated to use it though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM