web.xml部分

1.欢迎界面

<welcome-file-list>
  <welcome-file>/views/login.jsp</welcome-file>
</welcome-file-list>

2.字符编码过滤器

<filter>
  <filter-name>CharacterEncoding</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>CharacterEncoding</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

3.springmvc配置

<servlet>
  <servlet-name>springmvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:springmvc-servlet.xml</param-value>
  </init-param>

  <load-on-startup>1</load-on-startup>

</servlet>
<servlet-mapping>
  <servlet-name>springmvc</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

4.配置文件路径设置

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
</context-param>

springmvc-serlvet.xml部分

1.InternalResourceViewResolver 视图解析器

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/views/"></property>
  <property name="suffix" value=".jsp"></property>
</bean>

2.注解包扫描器

<context:component-scan base-package="cn.xin.controller" />

3.基础配置和引入静态资源配置

  方法一:

<mvc:annotation-driven />
<mvc:default-servlet-handler />

  方法二:

<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/images/" mapping="/images/**"/>

4.全局异常处理

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
  <property name="exceptionMappings">
    <props>
      <prop key="java.lang.RuntimeException">login</prop>
    </props>
  </property>
</bean>

5.拦截器配置
  1.针对HandlerMapper配置

<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
  <property name="interceptors">
    <list>
      <ref bean="hInterceptor1"/>
      <ref bean="hInterceptor2"/>
    </list>
  </property>
</bean>
<bean id="hInterceptor1" class="cn.com.mvc.interceptor.HandlerInterceptorDemo1"/>
<bean id="hInterceptor2" class="cn.com.mvc.interceptor.HandlerInterceptorDemo2"/>

  2.针对全局配置

<mvc:interceptors>
  <!-- 多个拦截器,顺序执行 -->
  <mvc:interceptor>
    <!-- /**表示所有url包括子url路径 -->
    <mvc:mapping path="/**"/>
    <bean class="cn.com.mvc.interceptor.HandlerInterceptorDemo1"/>
  </mvc:interceptor>
  <mvc:interceptor>
    <mvc:mapping path="/**"/>
    <bean class="cn.com.mvc.interceptor.HandlerInterceptorDemo2"/>
  </mvc:interceptor>
</mvc:interceptors>    

6.文件上传

<!-- 配置MultipartResolver,用于上传文件,使用spring的CommonsMultipartResolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <property name="maxUploadSize" value="5000000"/>
  <property name="defaultEncoding" value="utf-8"/>
</bean>

知识点部分

1.拦截器

1.实现HandlerInterceptor接口或者继承实现了该接口的类、实现WebRequestInterceptor接口或者继承实现了该接口的类2.HandlerInterceptor是针对请求的整个过程的,接口的方法中都含有response参数,而WebRequestInterceptor是针对请求的,接口的方法参数中没有response3.两种接口都含有三个方法:preHandle、postHandle、afterCompletion

2.Resetfule风格

1.url:/12.@RequestMapping设置路径:@RequestMapping(value="/xxxx/{id}",method={})3.@PathVariable指定参数:@PathVariable("id")Integer xxId

3.数据校验

...

Spring Mvc相关随笔的更多相关文章

  1. Spring MVC相关

    配置文件说明 web.xml, spring配置文件 applicationContext.xml, spring配置文件, mybatis连接mysql配置文件 sql-map-config-mys ...

  2. Spring MVC 相关资料整理

    来源于:http://www.cnblogs.com/ylhssn/p/4062757.html 1.概述 Spring MVC是一种基于Java实现MVC设计模式的请求驱动类型的轻量级Web框架,即 ...

  3. spring mvc相关问题

    1: 基于注解的SpringMVC简单介绍 2: spring组件扫描<context:component-scan/>使用详解 3: springMvc 注解配置例子

  4. 深入分析Spring 与 Spring MVC容器

    1 Spring MVC WEB配置 Spring Framework本身没有Web功能,Spring MVC使用WebApplicationContext类扩展ApplicationContext, ...

  5. spring mvc 快速入门

    ---------- 转自尚学堂 高淇 --------- Spring  MVC 背景介绍 Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块.使用 Spring 可插入的 MVC ...

  6. 准备学习Spring MVC

    这一系列笔记将带你一步一步的进入Spring MVC,高手勿喷. 首先你得安装以下的工具: JDK,虽然JDK8已经发布了一段时间了,但是由于我们并不会使用到里面的新特性,所以JDK6以上版本皆可以( ...

  7. Spring mvc web 配置

    Spring Framework本身没有Web功能, Spring MVC使用WebApplicationContext类扩展ApplicationContext ,使得拥有web功能.那么,Spri ...

  8. Spring mvc 模式小结

    http://www.taobaotesting.com/blogs/2375 1.spring mvc简介 Spring MVC框架是一个MVC框架,通过实现Model-View-Controlle ...

  9. Spring MVC + Spring MongoDB + Querydsl 通过maven整合实例

    效果图 一共3个页面:注册页,欢迎页,用户列表页 很简单的例子,主要是为了把流程走通,没有各种验证. 注册页: 欢迎页: 用户列表页: 源码地址 https://github.com/lemonbar ...

随机推荐

  1. 亲測Mysql表结构为InnoDB类型从ibd文件恢复数据

    客户的机器系统异常关机,重新启动后mysql数据库不能正常启动,重装系统后发现数据库文件损坏,悲催的是客户数据库没有进行及时备份,仅仅能想办法从数据库文件其中恢复,查找资料,试验各种方法,确认以下步骤 ...

  2. iOS开发--常用技巧 (MJRefresh详解)

         iOS开发--常用技巧 (MJRefresh详解) https://github.com/CoderMJLee/MJRefresh 下拉刷新01-默认 self.tableView.head ...

  3. RSA私钥加密公钥解密、各种密钥格式转换

    此随笔解决RSA加解密相关的3个问题,详情可以查看源码. 1.公钥加密.私钥解密2.各种格式RSA密钥之间的转换3.不限制加密原文的长度

  4. 点滴记录——Ubuntu 14.04中Chrome浏览器标题栏出现中文乱码

    今天不知道在系统里装的哪个软件与Chrome浏览器所用的字体向冲突了,导致标题栏显示的中文都变成了乱码,其次收藏栏中的中文也变成了乱码.导致原有的收藏内容都无法辨认了.在网上搜索了一下,也有人遇到了相 ...

  5. [英语学习]王秒同学《21天TED英语精练团》

    第一个分享: Chris Anderson的TED's secret to great public speaking(英音). There's no single formula for a gre ...

  6. ASP.NET Web Pages (Razor) API Quick Reference

    ASP.NET Web Pages (Razor) API Quick Reference By Tom FitzMacken|February 10, 2014 Print This page co ...

  7. html5--项目实战-仿360囧图

    html5--项目实战-仿360囧图 实例: 代码 <!doctype html> <html> <head> <meta charset="utf ...

  8. mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.String'

    在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter 来代替参数名. 正确的写法: <span style="f ...

  9. 性能-发挥ORACLE分区表

    ORACLE分区表发挥性能 http://www.cnblogs.com/zwl715/p/3962837.html 1.1 分区表PARTITION table 在ORACLE里如果遇到特别大的表, ...

  10. BZOJ_3479_[Usaco2014 Mar]Watering the Fields_Prim

    BZOJ_3479_[Usaco2014 Mar]Watering the Fields_Prim Description Due to a lack of rain, Farmer John wan ...