默认web.xml配置
默认的配置中,有2个servlet配置。default
和jsp
两个servlet。
default
处理默认请求,拦截<url-pattern>/</url-pattern>
请求。
jsp
处理JSP请求,拦截<url-pattern>*.jsp</url-pattern>
和<url-pattern>*.jspx</url-pattern>
请求。
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<!-- The mapping for the default servlet -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- The mappings for the JSP servlet -->
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
默认的session
超时配置是30
分钟
<!-- ==================== Default Session Configuration ================= -->
<!-- You can set the default session timeout (in minutes) for all newly -->
<!-- created sessions by modifying the value below. -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
提供了默认的欢迎页配置
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
项目中的web.xml配置
<context-param>
标签
<context-param>
<param-name>test</param-name>
<param-value>123456</param-value>
</context-param>
配置初始化参数,通过servlet
获取并进行逻辑操作。
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Enumeration<String> parameterNames = req.getServletContext().getInitParameterNames();
while (parameterNames.hasMoreElements()) {
String key = parameterNames.nextElement();
String value = req.getServletContext().getInitParameter(key);
System.out.println(key + ":" + value);
}
}
}
<session-config>
标签
<session-config>
<session-timeout>40</session-timeout><!--session有效期-->
<cookie-config>
<name>JSESSIONID</name><!--Cookie携带的key-->
<domain>www.gosuncn.fun</domain>
<path>/</path>
<comment>Session Cookie</comment>
<http-only>true</http-only><!--只能通过http请求携带,不能js脚本携带-->
<secure>false</secure><!--只能通过https协议请求访问-->
<max-age>3600</max-age><!--cookie有效期-->
</cookie-config>
<tracking-mode>COOKIE</tracking-mode><!--跟踪模式。除了COOKIE还有URL和SSL方式-->
</session-config>
<error-page>
标签配置错误页
<error-page>
<location>web.xml</location>
<error-code>500</error-code>
<exception-type>xxx</exception-type>
</error-page>