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. 海思HI3516A开发板顺利上线

    有图有真相.

  2. 【PA2013】【BZOJ3733】Iloczyn

    Description 给定正整数n和k,问是否能将n分解为k个不同正整数的乘积 Input 第一行一个数T(T<=4000)表示測试组数 接下来T行每行两个数n(n<=10^9),k(k ...

  3. Android SDK update被墙

    1.输入命令:$ sudo gedit /etc/hosts 2.在打开的 /etc/hosts 在文件的末尾添加下面一句:74.125.237.1 dl-ssl.google.com

  4. VS2010打开高版本VS解决方案

    http://blog.csdn.net/backspace110/article/details/62111273 Microsoft Visual Studio Solution File, Fo ...

  5. Codeforces 755 F. PolandBall and Gifts 多重背包+贪心

    F. PolandBall and Gifts   It's Christmas time! PolandBall and his friends will be giving themselves ...

  6. 设置一个DIV块固定在屏幕中央(两种方法)

    设置一个DIV块固定在屏幕中央(两种方法) 方法一: 对一个div进行以下设置即可实现居中. <style> #a{ position: fixed; top: 0px; left: 0p ...

  7. 设计模式-(6)适配器 (swift版)

    用来解决接口适配问题的三种模式:适配器模式,桥接模式,外观模式. 一,概念 适配器模式,将一个类的结构转换成用户希望的另一个接口,使得原本接口不兼容的类能在一起工作.换句话说,适配器模式就是链接两种不 ...

  8. YTU 1010: 目标柏林

    1010: 目标柏林 时间限制: 1000 Sec  内存限制: 64 MB 提交: 32  解决: 15 题目描述 1945年初,苏军和英美联军已从东西两面攻入德国国境. 4月初,在苏军和英美联军的 ...

  9. Android ConstraintLayout详解

    1. 概述 在本篇文章中,你会学习到有关ConstraintLayout -- 一种构建于弹性Constraints(约束)系统的新型Android Layout.最终你将会在Android Stud ...

  10. UVA - 1401 Remember the Word(trie+dp)

    1.给一个串,在给一个单词集合,求用这个单词集合组成串,共有多少种组法. 例如:串 abcd, 单词集合 a, b, cd, ab 组合方式:2种: a,b,cd ab,cd 2.把单词集合建立字典树 ...