简体   繁体   English

使用 Spring 的 Java EE 服务器中的 web.xml 文件的目的是什么?

[英]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:我是 spring 的新手,我想知道有关 Spring 的概念。我正在处理一个具有 web.xml 文件的 spring 项目,如下所示:

<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?我想知道这个 web.xml 是做什么的? 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.我建议您通读免费的在线书籍http://pdf.coreservlets.com ,我认为这是关于 Servlet 的最好的书籍之一。 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.简短的回答是:web.xml 用于配置 Web 应用程序的某些方面。 In the last servlet specification (3.0) it has become mostly obsolete.在最新的 servlet 规范 (3.0) 中,它已基本过时。 You can still use it, but for most things (like servlets) you can just use annotations nowadays.您仍然可以使用它,但是对于大多数事情(例如 servlet),现在您可以只使用注释。

If you're working with a container that doesn't support the Servlet 3.0 specification you're still obligated to use it though.如果您正在使用不支持 Servlet 3.0 规范的容器,您仍然有义务使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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