springMVC配置
创建后如果index.jsp报错重新新建就好。
添加jstl servlet springmvc相关配置
pom.xml
<!-- servlet --><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version></dependency><!-- end servlet --><!-- spring mvc --><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.3.12.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>4.3.12.RELEASE</version></dependency><!-- end spring mvc --><!-- jstl --><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!--end jstl -->
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><!-- spring 拦截器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- end spring 拦截器 --><!-- 加载 applicationContext.xml --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- 编码过滤器 --><filter><filter-name>encoding</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>encoding</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- end编码过滤器 --><!-- 设置监听 --><servlet><servlet-name>dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:dispatcher-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dispatcher</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!-- end设置监听 --><!-- 默认页面 --><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list> </web-app>
创建两个xml applicationContext.xml用于配置数据库、事物等,dispatcher-servlet.xml配置试图层相关
applicationContext.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:p="http://www.springframework.org/schema/p"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"></beans>
dispatcher-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:p="http://www.springframework.org/schema/p"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!-- 定义controller扫描包 --><context:component-scan base-package="com.example.controller" /><!-- 启动注释模式 --><mvc:annotation-driven /><!-- 处理静态资源 --><mvc:default-servlet-handler /><!-- 设置不过滤内容 --><mvc:resources location="/*.html" mapping="/**.html" /><mvc:resources location="/css/*" mapping="/css/**" /><mvc:resources location="/js/*" mapping="/js/**" /><mvc:resources location="/images/*" mapping="/images/**" /><!-- 配置视图解析器 --><bean id="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass"value="org.springframework.web.servlet.view.JstlView" /><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp" /></bean> </beans>
转载于:https://www.cnblogs.com/hufeng1989/p/7778527.html
springMVC配置相关推荐
- springmvc配置DispatcherServlet拦截url注意事项
<!-- 前端控制器 --><servlet><servlet-name>springmvc</servlet-name><servlet-cla ...
- 第9步 spring 配置 springmvc配置
spring配置 有5个网址 springboot 再讲一遍 spring的学习最好的方法是运行 官方demo 学习它里面的配置 . 我们不可能一下子理解spring里面的源码 spri ...
- SpringMVC配置静态资源加载, 中文乱码处理,注解驱动
常规配置(Controller加载控制) SpringMVC的处理器对应的bean必须按照规范格式开发,未避免加入无效的bean可通过bean加载过滤器进行包含设定或排除设定,表现层bean标注通常设 ...
- spring boot实现WebMvcConfigurer接口定制SpringMvc配置
文章目录 自定义静态资源映射 addResourceHandlers() 拦截器 addInterceptors() 无业务逻辑页面跳转 addViewControllers() 合而为一 sprin ...
- SpringMVC配置任何类型转换器 Converter(以时间类型为例)
SpringMVC配置任何类型转换器 Converter (以时间类型为例) 从页面传到后台的时间字符串转成日期格式封装到实体类 1. 定义时间DateConverter转换类实现 Converte ...
- SpringMVC配置自定义过滤器
SpringMVC配置自定义过滤器 环境 开发工具: idea2019.3.5 springmvc版本: 5.1.9.RELEASE <dependency><groupId> ...
- spring boot web开发------自定义springmvc配置
1.如何自定义springmvc配置 旧的springmvc配置文件 <?xml version="1.0" encoding="UTF-8"?> ...
- 关于idea使用SpringMVC配置正确却404问题及解决办法
今天在学习SpringMVC的时候,配置文件完全正确,可是一直 404. 同时检查了依赖,也没有问题.后面发现是idea自身问题. 具体解决办法如下: 重启tomcat,发现可以正确访问了. 总结: ...
- spring与springMVC配置扫描的问题
为什么80%的码农都做不了架构师?>>> 首先,如果不配置事务在哪里扫描都是可以的,但是这是不可能的,所以扫描的时候就需要有先后的顺序. 顺序:spring负责除control ...
- Spring框架深入(四)--SpringMVC配置详解
一.SpringMVC web模型 二.@RequestMapping参数说明 1.value:定义处理方法的请求的URL地址: 2.method:定义处理的方法的http method类型,如GET ...
最新文章
- 浅析Struts 体系结构与工作原理(图)
- Linux进程的分析和执行过程
- leetcode 412. Fizz Buzz
- 1. Leetcode 1. 两数之和 (数组-双向双指针)
- 第二章 数据类型和文件操作
- HDU 1251 统计难题(Trie模版题)
- 普通用户杜绝不请自来的邮件对策
- xcorr函数_相关函数xcorr的用法及实例
- bootstrap-pagination demo
- visual studio(vs)中项目解决方案的目录组织安排
- 关于信道利用率的总结与一道习题的最终解释
- latex模板——计算机学报
- IMSettings 1.5.1 发布,输入法设置工具
- css内联样式!important
- h5算命php源码,H5付费算命PHP源码那么火_付费算命源码如何下载
- 网络层和传输层各种协议
- excel两个指标相关性分析_相关分析与回归分析 Excel 和 R计算皮尔逊相关系数(Pearson correlation)...
- 名企招聘面试考题集锦
- Android Studio的报错提示:Error while Launching activity
- JAVA 垃圾回收
热门文章
- Intellij IDEA连接Spark集群
- 2015年传智播客JavaEE 第168期就业班视频教程day38-SSH综合案例-1
- C/C++中printf和C++中cout的输出格式
- 如何利用FNDLOAD更新FORM的Personalization(Moving Personalizations between instances)
- LeetCode(657)——机器人能否返回原点(JavaScript)
- JavaScript学习(七十四)—递归函数
- ES6学习(五)—数组的扩展
- idea gui插件_「Java」 - 自写IntelliJ IDEA插件
- mybatis批量删除和插入
- 生活中有哪些越早明白越好的道理?