What is web.xml file and what are all things can I do with it?

前端 未结 8 957
-上瘾入骨i
-上瘾入骨i 2020-11-30 17:18

The web.xml Deployment Descriptor Elements in Oracle\'s BEA WebLogic Server 8.1 Documentation pretty much sums up each element in a web.xml file. But I am also curious about

相关标签:
8条回答
  • 2020-11-30 17:59

    What is web.xml file and what all things can I do with it ?

    The /WEB-INF/web.xml file is the Web Application Deployment Descriptor of your application. This file is an XML document that defines everything about your application that a server needs to know (except the context path, which is assigned by the Application Deployer and Administrator when the application is deployed): servlets and other components like filters or listeners, initialization parameters, container-managed security constraints, resources, welcome pages, etc.

    Note that reference you mentioned is pretty old (Java EE 1.4), there have been few changes in Java EE 5 and even more in Java EE 6 (which makes the web.xml "optional" and introduces Web Fragments).

    Is there any configuration parameter which should be avoided like plague?

    No.

    Any parameters related to performance or memory usage?

    No, such things are not configured at the application level but at the container level.

    Security related risk due to common mis-configuration ?

    Well, if you want to use container-managed security constraints and fail at configuring them properly, resources won't obviously be properly protected. Apart from that, the biggest security risks come from the code you'll deploy IMO.

    0 讨论(0)
  • 2020-11-30 18:01

    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    

    0 讨论(0)
  • 2020-11-30 18:06

    I am trying to figure out exactly how this works too. This site might be helpful to you. It has all of the possible tags for web.xml along with examples and descriptions of each tag.

    http://wiki.metawerx.net/wiki/Web.xml

    0 讨论(0)
  • 2020-11-30 18:12
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet>
        <description></description>
        <display-name>pdfServlet</display-name>
        <servlet-name>pdfServlet</servlet-name>
        <servlet-class>com.sapta.smartcam.servlet.pdfServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>pdfServlet</servlet-name>
        <url-pattern>/pdfServlet</url-pattern>
      </servlet-mapping>
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
      </context-param>
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    
    0 讨论(0)
  • 2020-11-30 18:13
    1. No, there isn't anything that should be avoided
    2. The parameters related to performance are not in web.xml they are in the servlet container configuration files (server.xml on tomcat)
    3. No. But the default servlet (mapped in a web.xml at a common location in your servlet container) should preferably disable file listings (so that users don't see the contents of your web folders):

      listings true

    0 讨论(0)
  • 2020-11-30 18:13

    If using Struts, we disable direct access to the JSP files by using this tag in web.xml

     <security-constraint>
    <web-resource-collection>
      <web-resource-name>no_access</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint/>
    

    0 讨论(0)
提交回复
热议问题