spring mvc中web.xml的配置

<?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"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   id="WebApp_ID" version="2.5">
   <!--display-name显示的是项目的名称-->
   <display-name>educate-web</display-name>
<!--错误码的跳转到指示页-->
   <error-page>
      <error-code>400</error-code>
      <location>/page/login.html</location>
   </error-page>
   <error-page>
      <error-code>404</error-code>
      <location>/page/login.html</location>
   </error-page>
   <error-page>
      <error-code>405</error-code>
      <location>/page/login.html</location>
   </error-page>
   <error-page>
      <error-code>500</error-code>
      <location>/page/login.html</location>
   </error-page>

   <!--Spring的ApplicationContext 载入 配置文件的位置,可以使用统配字符*进行模糊配置-->
   <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/applicationContext*.xml</param-value>
   </context-param>
   <!--监听器的配置  它会在web服务启动时,根据contextConfigLocation中声明spring配置文件位置载入配置信息,需要注意的是,他不会载入DispatcherServlet已经载入的配置文件-->
   <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>

   <!-- 过滤编码方式,防止乱码,解决POST乱码 -->
   <filter>
      <filter-name>CharacterEncodingFilter</filter-name>
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
         <param-name>encoding</param-name>
         <param-value>utf-8</param-value>
      </init-param>
   </filter>
   <filter-mapping>
      <filter-name>CharacterEncodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>

   <!-- SpringMVC入口  name是可以随意定义的,但是class是包名 -->
   <servlet>
      <!--审批ringmvc的核心分发器,它会默认自动加载web—inf文件夹下的<servlet-name>下servlet.xml文件,在这里,我们的servlet-name为springmvc-->
      <!--servlet-name 是servlet的名称,但是servlet-class是servlet所引用的类名-->
      <servlet-name>educate-web</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <!--加载spring mvc的配置文件-->
      <!--如果我们的配置文件不在默认路径下,我们需要配置<init-param>contextConfigLocation-->
      <init-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>classpath:spring/educate-web-servlet.xml</param-value>
      </init-param>
      <!--设置当前servlet在所有servlet中第一个启动-->
      <load-on-startup>1</load-on-startup>
   </servlet>
   <!--配置educate-web控制器的拦截url,默认所有的*.html都拦截-->
   <servlet-mapping>
      <servlet-name>educate-web</servlet-name>
      <url-pattern>*.html</url-pattern>
   </servlet-mapping>

<!--session是有浏览器和服务器之间的维护,session超时可以理解为:在浏览器和服务器之间创建了一个session,要是长时间没有没有交互,服务器将此销毁session-->
   <session-config>
      <session-timeout>60</session-timeout>
      <!--客户端连续两次与服务器交互间隔时间最长为2分钟,2分钟之后session。getAttribute()获取的值为空-->
   </session-config>
<!--欢迎页的配置-->
   <welcome-file-list>
      <welcome-file>/page/login.html</welcome-file>
   </welcome-file-list>
</web-app>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值