一、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前端控制器的更多相关文章

  1. Spring之SpringMVC前端控制器DispatcherServlet(源码)分析

    1.DispatcherServlet作用说明 DispatcherServlet提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring IoC容器无缝集成,从而可以获得 ...

  2. springmvc前端控制器的三种拦截方式

    *.do :只拦截.do文件 / :拦截除jsp页面的所有请求,包括restful类型的url /*  :拦截所有请求包括jsp页面

  3. SpringMVC前端控制器以.html后缀拦截,访问接口返回406问题

    原因: spring监测到是.html来访问,它就会认为需要返回的是html页面.如果返回的不是html,会报406错误 解决: 提供多种后缀拦截方式,工程里web.xml配置 分析: HTTP 40 ...

  4. springmvc前端控制器拦截路径的配置报错404

    1.拦截"/",可以实现现在很流行的REST风格.很多互联网类型的应用很喜欢这种风格的URL.为了实现REST风格,拦截除了jsp的所有. 2.拦截/*,拦截所有访问,会导致404 ...

  5. 淘淘商城之springmvc和mybatis整合

    一.需求 使用springmvc和mybatis完成商品列表查询 二.整合思路 springmvc+mybaits的系统架构: 第一步:整合dao层 mybatis和spring整合,通过spring ...

  6. (转)淘淘商城系列——SSM框架整合之Dao层整合

    http://blog.csdn.net/yerenyuan_pku/article/details/72721093 一个项目中往往有三层即Dao层.Service层和Web层,看标题就知道了,本文 ...

  7. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第五天(非原创)

    文章大纲 一.课程介绍二.前台系统(门户系统)搭建介绍三.前台系统(门户系统)搭建实战四.js请求跨域解决五.项目源码与资料下载六.参考文章   一.课程介绍 一共14天课程(1)第一天:电商行业的背 ...

  8. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第二天(非原创)

    文章大纲 一.课程介绍二.整合淘淘商城ssm项目三.Mybatis分页插件PageHelper使用四.整合测试五.项目源码与资料下载六.参考文章   一.课程介绍 一共14天课程(1)第一天:电商行业 ...

  9. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第五天】

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

随机推荐

  1. webpack4.x相关笔记整理

    概念 Webpack是一个模块打包机,它可以将我们项目中的所有js.图片.css等资源,根据其入口文件的依赖关系,打包成一个能被浏览器识别的js文件.能够帮助前端开发将打包的过程更智能化和自动化. W ...

  2. 微信小程序不能超过十个并发的解决办法

    一般是封装一个请求队列,将请求对象存入队列,在complete写队列的出队操作.

  3. Quartz.NET 前一次任务未执行完成时不触发下次的解决方法

    如图所示,在Job 上 加     [DisallowConcurrentExecution]        特性

  4. linux利用CMakeLists编译程序或生成库文件

    #设置CMAKE最低版本 CMAKE_MINIMUM_REQUIRED(VERSION 2.8) #设置项目名称 SET(PROJECT_NAME Image_Test_01) #建立项目 PROJE ...

  5. AT2364 Colorful Balls

    AT2364 Colorful Balls 题意翻译 N个球排成一排,第i个球有颜色ci和重量wi. Snuke每次可以选择两个颜色相同,且重量之和不超过X的球,交换他们的位置. Snuke每次可以选 ...

  6. String在内存中如何存储(Java)

    JDK1.8中JVM把String常量池移入了堆中,同时取消了“永久代”,改用元空间代替(Metaspace)java中对String对象特殊对待,所以在heap区域分成了两块,一块是字符串常量池(S ...

  7. linux shell脚本报错总结

    1  rizhi.sh: line 28: warning: here-document at line 9 delimited by end-of-file (wanted `EOF') 原因是末尾 ...

  8. Django-website 程序案例系列-8 html模板文件详解

    主模板:master.html <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  9. Nodejs+Express+Mysql实现简单用户管理增删改查

    源码地址 https://github.com/king-y/NodeJs/tree/master/user 目录结构 mysql.js var mysql = require('mysql'); v ...

  10. UVA11401-Triangle Counting-递推

    给出一个数字n,计算从1到n能组成几个不同的三角形. n的范围是10^6,大概就是递推吧.从F[i-1]到F[i]可以线性求出.要注意结果超出int. #include <cstdio> ...