您的位置:首页 > 编程语言 > Java开发

spring框架的基本配置信息 web.xml 配置

2018-10-28 12:47 267 查看
版权声明:转载请注明出处 https://blog.csdn.net/langruu/article/details/83473676

使用spring,spring-mvc,MyBatis ssm整合框架开发,一个基本的web.xml配置。

最下面代码可以直接粘贴到web项目中WEB-INF下的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">
  <!-- 默认首页 -->
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <!-- 配置spring-MVC核心控制器 -->
  <servlet>
      <!-- 自定义个控制器名 -->
    <servlet-name>spring</servlet-name>
    <!-- 配置spring-MVC所在的包,即完全限定名 -->
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 如果spring-servlet.xml文件没有放在WEB-INF,放在src目录下,需配置此项 -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/classes/spring-servlet.xml</param-value>
    </init-param>
    <!-- 设置被加载的顺序 (优先级)-->
    <load-on-startup>0</load-on-startup>
  </servlet>
  <!-- 配置启用控制器的路径(‘/’)标识所有有路径都会转到控制器中去找方法 -->
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <!-- 配过滤器 -->
  <filter>
    <!-- 起名,并加载过滤器类 -->
    <filter-name>encodingFilter</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>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <!-- 配置过滤器路径 -->
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- 配置spring框架 --> 
  <!-- 配置spring框架监听 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 配置加载spring配置文件applicationContent.xml -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
</web-app>

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: