淘淘商城之springmvc前端控制器
一、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>springwebmvc</display-name> <!-- springmvc前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--
contextConfigLocation配置springmvc加载的配置文件(配置处理器映射器、适配器等等) 如果不
配置contextConfigLocation,默认加载的是/WEB-INF/servlet名称-serlvet.xml(springmvc-servlet.xml)
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!--
第一种:*.action,访问以.action结尾 由DispatcherServlet进行解析;
第二种:/,所以访问的地址都由DispatcherServlet进行解析,对于静态文件的解析需要配置不
让DispatcherServlet进行解析 使用此种方式可以实现 RESTful风格的url;
第三种:/*,这样配置不对,使用这种配置,最终要转发到一个jsp页面时,
仍然会由DispatcherServlet解析jsp地址,不能根据jsp页面找到handler,会报错
-->
<url-pattern>*.action</url-pattern>
</servlet-mapping> <!-- <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> -->
</web-app>
二、springmvc.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- 配置第一种Handler,ItemsController1需要实现Controller接口-->
<!-- <bean id="itemsController1" name="/queryItems.action" class="com.chuanye.ssm.controller.ItemsController1" /> -->
<!-- 配置第二种Handler,ItemsController2需要实现HttpRequestHandler接口 -->
<!-- <bean id="itemsController2" class="com.chuanye.ssm.controller.ItemsController2" /> --> <!-- 对于注解的Handler可以单个配置; 实际开发中建议使用组件扫描-->
<bean class="com.chuanye.ssm.controller.ItemsController3" />
<!-- 可以扫描controller、service等; 这里让扫描controller,指定controller的包 -->
<!-- <context:component-scan base-package="com.chuanye.ssm.controller" /> --> <!-- 《非注解映射器1》 -->
<!-- <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> -->
<!-- 《非注解映射器2》 -->
<!-- <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
对itemsController1进行url映射,url是/queryItems1.action
<prop key="/queryItems1.action">itemsController1</prop>
<prop key="/queryItems2.action">itemsController1</prop>
<prop key="/queryItems3.action">itemsController2</prop>
</props>
</property>
</bean> --> <!-- 《注解映射器》 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<!-- 《注解适配器》 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<!--
使用 mvc:annotation-driven代替上边注解映射器和注解适配器配置
mvc:annotation-driven默认加载很多的参数绑定方法,比如json转换
解析器就默认加载了,如果使用mvc:annotation-driven不用配置上边的
RequestMappingHandlerMapping和RequestMappingHandlerAdapter
实际开发时使用mvc:annotation-driven
-->
<mvc:annotation-driven></mvc:annotation-driven> <!-- 《非注解适配器1》 -->
<!-- <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> -->
<!-- 《非注解适配器2》 -->
<!-- <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/> --> <!-- 《视图解析器》 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<!-- 配置jsp路径的前缀 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!-- 配置jsp路径的后缀 -->
<property name="suffix" value=".jsp"/>
</bean> </beans>
淘淘商城之springmvc前端控制器的更多相关文章
- Spring之SpringMVC前端控制器DispatcherServlet(源码)分析
1.DispatcherServlet作用说明 DispatcherServlet提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring IoC容器无缝集成,从而可以获得 ...
- springmvc前端控制器的三种拦截方式
*.do :只拦截.do文件 / :拦截除jsp页面的所有请求,包括restful类型的url /* :拦截所有请求包括jsp页面
- SpringMVC前端控制器以.html后缀拦截,访问接口返回406问题
原因: spring监测到是.html来访问,它就会认为需要返回的是html页面.如果返回的不是html,会报406错误 解决: 提供多种后缀拦截方式,工程里web.xml配置 分析: HTTP 40 ...
- springmvc前端控制器拦截路径的配置报错404
1.拦截"/",可以实现现在很流行的REST风格.很多互联网类型的应用很喜欢这种风格的URL.为了实现REST风格,拦截除了jsp的所有. 2.拦截/*,拦截所有访问,会导致404 ...
- 淘淘商城之springmvc和mybatis整合
一.需求 使用springmvc和mybatis完成商品列表查询 二.整合思路 springmvc+mybaits的系统架构: 第一步:整合dao层 mybatis和spring整合,通过spring ...
- (转)淘淘商城系列——SSM框架整合之Dao层整合
http://blog.csdn.net/yerenyuan_pku/article/details/72721093 一个项目中往往有三层即Dao层.Service层和Web层,看标题就知道了,本文 ...
- ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第五天(非原创)
文章大纲 一.课程介绍二.前台系统(门户系统)搭建介绍三.前台系统(门户系统)搭建实战四.js请求跨域解决五.项目源码与资料下载六.参考文章 一.课程介绍 一共14天课程(1)第一天:电商行业的背 ...
- ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第二天(非原创)
文章大纲 一.课程介绍二.整合淘淘商城ssm项目三.Mybatis分页插件PageHelper使用四.整合测试五.项目源码与资料下载六.参考文章 一.课程介绍 一共14天课程(1)第一天:电商行业 ...
- 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第五天】
https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...
随机推荐
- html 列表 ol 、ul 、dl
html的列表分為無序列表(ul).有序列表(ol).自定義列表(dl). 無序列表: 以<ul>開始,列表項以<li>開始: 列表項可以是段落.圖像.連接.換行符.列表等: ...
- 洛谷 P4294 [WC2008]游览计划
题目链接 不是很会呢,但似乎抄了题解后有点明白了 sol:状态DP显然,其实是要构建一棵最小生成树一样的东西,我自己的理解(可能不是很对哦希望多多指教)f[x][y][zt]就是到x,y这个点,状态为 ...
- Nodejs+Express+Mysql实现简单用户管理增删改查
源码地址 https://github.com/king-y/NodeJs/tree/master/user 目录结构 mysql.js var mysql = require('mysql'); v ...
- C# 枚举值 (二) 多属性 操作
很多时候,我们的枚举值可能需要中英文, 那么可以使用下面的方法: 下面这个类,包含2部分. 1 BaseDescriptionAttribute特性的重载 2 枚举的操作类 EnumOperate n ...
- Studio启动的时候报错 Could not install Gradle distribution from
安装了studio以后,直接点击[Start]报如下错,绝对不是网络的问题. Could not install Gradle distribution from 'https://services. ...
- Java“禁止”泛型数组
Java“禁止”泛型数组 原文:https://blog.csdn.net/yi_Afly/article/details/52058708 1. 泛型定义泛型编程是一种通过参数化的方式将数据处理与数 ...
- 【BZOJ2000】[HNOI2000]取石头游戏(贪心,博弈论)
[BZOJ2000][HNOI2000]取石头游戏(贪心,博弈论) 题面 BZOJ 洛谷 题解 这题好神仙啊,窝不会QaQ. 假装一下只有三个元素\(a_{i-1},a_i,a_{i+1}\),并且满 ...
- SharePoint 错误集
1. Delete a site collection · Run command : Remove-SPSite –Identity http://ent132.sharepoint.hp.com/ ...
- Windows Server 2008配置Network Load Balancing(服务群集)
最近配置SharePoint 2013 WFE 时,客户提到要让多台WFE能load balance,于是研究了下Network Load Balancing. 当把一台服务器 ...
- luogu1514 [NOIp2010]引水入城 (bfs+记忆化搜索)
我们先bfs一下看看是否能到最底下的所有点 如果不能的话,直接把不能到的那几个数一数就行了 如果能的话: 可以发现(并不可以)某格能到达的最底下的格子一定是一个连续的区间 (因为如果不连续的话,我们先 ...