码迷,mamicode.com
首页 > 编程语言 > 详细

19-spring学习-springMVC环境配置

时间:2018-01-07 00:54:36      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:ppi   round   实现   pre   utf-8   证明   splay   http   过滤器   

新建一共环境,添加spring支持,就可以开发springMVC了。

既然是springMVC,就必须为其定义相关配置。

1,springMVC所有配置都需要在applicationContext.xml中定义。

范例:修改配置文件

添加这几个支持:

技术分享图片

 发现配置中已经支持了

技术分享图片

对springMVC进行annotation的配置

    <!-- SpringMVC也是基于Annotaion实现的配置,启用annotation -->
    <context:annotation-config/>    <!-- 支持annotation -->
    <context:component-scan base-package="com.SpringMVC"/>        <!-- 指定扫描包 -->
    
    <!-- 定义springMVC处理 ,表示springMVC中将支持annotation-->
    <mvc:annotation-driven/>
    <mvc:default-servlet-handler/>

2,配置web.xml文件

最好MVC设计,所有的控制器依然使用Servlet完成,而springMVC支持支持Servlet处理。

Servelet类:DispatcherServlet

范例:修改web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>SpringMVC</display-name>
  
  <!-- 此部分的操作是负责Spring容器启动的,即便使用springMVC也不能缺少此配置 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
 <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  
  <!-- 配置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:applicationContext.xml</param-value>
      </init-param>
  </servlet>
  
  <servlet-mapping>
      <servlet-name>SpringMVC</servlet-name>
      <url-pattern>*.action</url-pattern>
  </servlet-mapping>
  
</web-app>

此处使用了servelet进行了所有action的处理,那么也就证明了,在开发中,过滤器可以实现所有验证操作。

 

 

 

  

 

19-spring学习-springMVC环境配置

标签:ppi   round   实现   pre   utf-8   证明   splay   http   过滤器   

原文地址:https://www.cnblogs.com/alsf/p/8215767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!