SpringMVC(二)配置文件
来源:互联网 发布:steam mac 编辑:程序博客网 时间:2024/06/18 10:52
了解SpringMVC后,接下来我们学习它的配置文件:
1、新建WEB项目:
2、在WebContent-WEB-INF下的lib文件里导入jar包:
由于SpringMVC是基于表现层的框架,所以我们建的是Web项目,这里也需要导入servlet.jar
3、配置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_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>springMVC01</display-name> <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> <!-- 第一部分 --> <!-- 配置SpringMVC前端控制器 --> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 启动WEB容器自动加载前端控制器 --> <load-on-startup>1</load-on-startup> </servlet> <!-- SpringMVC前端控制器 映射 --> <servlet-mapping> <servlet-name>springMVC</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> </filter> <!-- 配置字符集编码过滤器映射 --> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 第三部分 --> <!-- 配置加载springMVC框架环境配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springMVC-servlet.xml</param-value> </context-param> <!-- 监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener></web-app>
4、创建springMVC-servlet.xml配置文件(文件名为固定格式)
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- 配置处理器映射 (必配项) --> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> <!-- 配置页面处理器适配器 (必配项) --> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> <!-- 配置视图解析器(必配项) --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <!-- 设置视图前缀 --> <property name="prefix" value="" /> <!-- 设置视图后缀 --> <property name="suffix" value=".jsp"/> </bean> <!-- 配置访问静态资源 (必配项)--> <mvc:default-servlet-handler/></beans>
基本配置就配置完成了!
阅读全文
0 0
- SpringMVC(二)配置文件
- springmvc + shiro 配置(二、其他配置文件)
- SpringMVC学习笔记(二)-----配置文件
- SpringMVC配置文件
- SpringMVC配置文件
- springMvc配置文件
- SpringMVC配置文件
- SpringMVC配置文件
- springmvc配置文件
- springMVC配置文件
- SpringMVC 配置文件
- springmvc配置文件
- springMVC配置文件
- SpringMVC配置文件
- SpringMVC 配置文件
- springmvc 配置文件
- SpringMvc 配置文件
- springmvc配置文件
- 前端视角漫谈百度ueditor编辑器前后端分离配置
- 【greenplum】greenplum 如何删除临时schema(孤立schema)
- springmvc返回json参数封装
- Java内存溢出(OOM)异常完全指南【转】
- druid源码解读
- SpringMVC(二)配置文件
- 美团云深度学习平台-快速开始
- Win下必备神器之Cmder
- 查看被占用的端口号,并杀死它
- RecyclerView学习
- 对一个字符串进行...(未完待续)
- 集合类关系
- 一次简单的自定义注解体
- Linux Shell命令大全(持续更新)