什么是web.xml文件,我可以用它做什么?

Oracle的BEA WebLogic Server 8.1文档中的web.xml部署描述符元素几乎总结了web.xml文件中的每个元素。 但我也很好奇以下几点:

  1. 有什么configuration参数应该像鼠疫一样避免吗?
  2. 任何与性能或内存使用有关的参数?
  3. 安全相关的风险由于常见的错误configuration?

除了元素名称和用法,还有什么我应该知道的web.xml?

什么是web.xml文件,我可以用它做什么?

/WEB-INF/web.xml文件是应用程序的Web应用程序部署描述符。 此文件是一个XML文档,它定义了服务器需要了解的所有应用程序(除了部署应用程序时由Application Deployer和Administrator分配的上下文path):servlet和其他组件,如filter或侦听器,初始化参数,容器pipe理的安全约束,资源,欢迎页面等

请注意,您提到的引用是相当古老的(Java EE 1.4),Java EE 5中甚至更less,Java EE 6中的更改 (使web.xml “可选”并引入Web碎片 ) 几乎没有变化 。

有什么configuration参数应该像鼠疫一样避免吗?

没有。

任何与性能或内存使用有关的参数?

不,这样的事情不是在应用程序级别configuration,而是在容器级别configuration。

安全相关的风险由于常见的错误configuration?

那么,如果你想使用容器pipe理的安全约束,并没有正确configuration它们,资源显然不会得到适当的保护。 除此之外,最大的安全风险来自您将部署IMO的代码。

除了元素名称和用法之外,我应该了解什么关于web.xml?

ALL TIME最重要的JSPconfiguration参数是在你的web.xml中。 女士们,先生们,我给你… TRIM-DIRECTIVE-WHITESPACES选项!

 <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <trim-directive-whitespaces>true</trim-directive-whitespaces> </jsp-property-group> </jsp-config> 

如果您使用任何标记库(循环特别丑陋和浪费),则会删除您在生成的HTML中获得的数百或数千行空白空间。

另一个重要的是默认的网页(当你没有在URL中input网页时,你自动发送的页面):

 <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> 
  1. 不,没有什么应该避免的
  2. 与性能相关的参数不在web.xml它们位于servlet容器configuration文件(tomcat上的server.xml
  3. 但是,默认的servlet(映射在servlet容器中的常见位置的web.xml中)最好禁用文件列表(以便用户不会看到Web文件夹的内容):

    列表为真

我正试图弄清楚这是如何工作的。 此网站可能对您有所帮助。 它具有web.xml的所有可能的标签,以及每个标签的示例和描述。

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

如果使用Struts,我们通过在web.xml中使用这个标签来禁止直接访问JSP文件

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

部署描述符文件 “web.xml”:通过正确使用部署描述符文件web.xml,可以控制Web应用程序行为的许多方面,从预加载servlet,限制资源访问到控制会话超时。

web.xml :用于控制Web应用程序的许多方面。 使用web.xml,您可以分配用于调用servlet的自定义URL,为整个应用程序指定初始化参数以及特定的servlet,控制会话超时,声明filter,声明安全angular色,根据声明的安全angular色限制对Web资源的访问,等等。

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> 
 <?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>