Oracle BEA WebLogic Server 8.1文档中的web.xml部署描述元素基本上总结了每个web.xml文件中的元素。但我还对以下内容感到好奇:
- 有没有应该像瘟疫一样避免的配置参数?
- 是否存在与性能或内存使用相关的参数?
- 由于常见的错误配置而导致的安全风险?
除了元素名称及其用法之外,还应了解web.xml的哪些内容?
Oracle BEA WebLogic Server 8.1文档中的web.xml部署描述元素基本上总结了每个web.xml文件中的元素。但我还对以下内容感到好奇:
除了元素名称及其用法之外,还应了解web.xml的哪些内容?
web.xml
“可选”,并引入了Web片段)。
是否有应该像瘟疫一样避免的配置参数?
没有。
任何与性能或内存使用相关的参数吗?
没有,这些东西不是在应用程序级别配置,而是在容器级别配置。
由于常见的错误配置而导致的安全相关风险?
好吧,如果您想使用容器管理的安全约束,并且在正确配置它们方面失败,资源显然不会得到适当的保护。除此之外,我认为最大的安全风险来自您部署的代码。
除了元素名称和使用方法外,我需要了解哪些关于web.xml的知识?
在您的web.xml中,有一个最重要的JSP配置参数,它就是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中没有输入网页时自动跳转到的页面):
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
web.xml
中,它们在servlet容器配置文件中(例如,在tomcat上是server.xml
)。不需要。但是默认的servlet(在您的servlet容器中的公共位置映射为一个web.xml)最好禁用文件列表(这样用户就看不到您的网页文件的内容):
listings true
<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的初始化参数,控制会话超时,声明过滤器,声明安全角色,根据声明的安全角色限制对Web资源的访问等等。
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
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>