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. android真机调试 INSTALL_FAILED_MEDIA_UNAVAILABLE 问题解决方案

    前提是手机用数据线连到电脑,安装好手机对应的驱动. 1:打开cmd 2:cd切换到sdk安装目录的platform-tools目录,比如我安装到了D盘根目录,则输入: cd d:\android-sd ...

  2. ExtJs里表格自动显隐滚动条

    ExtJs里面,layout:'border'这种布局应该很常用,但我用的时候,因为不熟,走了一些弯路.比如说,一个页面,大体布局是这样的: 上:查询输入框 中+下:查询结果(表格,底部有分页控件) ...

  3. flask的CBV,flash,Flask-Session,及WTForms-MoudelForm

    1,CBV: from flask import vews class LoginView(views.MethodView): def get(self): return "雪雪其实也很好 ...

  4. hdfs对namenode format 之后 应该首先检查内存消耗情况,以判断是否支持开启yarn

    http://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-common/yarn-default.xml  3.0.0 yarn.sc ...

  5. sql 语法树 常量

    SELECT id,'|',url,'|',update_time FROM tab LIMIT 10;SELECT COUNT(1) AS parent,(SELECT COUNT(1) FROM ...

  6. Enterprise Architect 生成项目类图

    Enterprise Architect使用教程: https://blog.csdn.net/chenglc1612/article/details/81083151 主要流程 --到此-自动生成完 ...

  7. linux 下RTL8723/RTL8188调试记录(命令行)【转】

    本文转载自:http://blog.h5min.cn/wuhongxin123/article/details/41820877 本文是在正确安装好wifi驱动后对系统进行的配置. 1.   配置wp ...

  8. C# WinForm开发系列 - Form/Window

    Form是WinForm开发中非常重要的一个控件, 本文将包含如何制作一个关于对话框,系统载入提示窗体, 创建类似于QQ提示框以及创建不规则窗体等(文章及相关代码搜集自网络,仅供学习参考,版权属于原作 ...

  9. spark安装和登陆配置

    1.下载安装包: http://www.igniterealtime.org/downloads/index.jsp 2.点击安装后打开登陆界面: 2.点击“高级”,设置相关配置: 3.点击“登陆”后 ...

  10. 四:网络--NSURLConnection基本使用

    一.NSURLConnection的常用类 (1)NSURL:请求地址 (2)NSURLRequest:封装一个请求,保存发给服务器的全部数据,包括一个NSURL对象,请求方法.请求头.请求体.... ...