maven搭建ssm框架之web.xml文件

使用maven搭建ssm框架的web.xml的配置:
    


web.xml基本设置:
   1.启动spring容器:applicationContext.xml---------ContextLoaderListener
   2.前端控制器:可指定路径和不指定(web-inf下面加-servlet)spring-mvc.xml------DispatcherServlet
   3.字符编码过滤器,放在所有过滤器之前  ---------CharacterEncodingFilter


<!-- needed for ContextLoaderListener -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:spring-context.xml</param-value>
 </context-param>

 <!-- Bootstraps the root web application context before servlet initialization -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 
 <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
 <servlet>
  <servlet-name>springDispatcherServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:spring-mvc.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>

 <!-- Map all requests to the DispatcherServlet for handling -->
 <servlet-mapping>
  <servlet-name>springDispatcherServlet</servlet-name>
  <url-pattern>url</url-pattern>
 </servlet-mapping>
 
 <filter>
  <filter-name>encoding-filter</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>
  <init-param>
   <param-name>forceRequestEncodig</param-name>
   <param-value>true</param-value>
  </init-param>
  <init-param>
   <param-name>forceResponseEncoding</param-name>
   <param-value>true</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>encoding-filter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <filter>
  <filter-name>hidden-filter</filter-name>
  <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>hidden-filter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

    上述是web.xml文件最基本的配置,除此之外,每个人可以根据自己的情况设置自己的一些东西。

猜你喜欢

转载自blog.csdn.net/mengdeng19950715/article/details/79306794
今日推荐