zoukankan      html  css  js  c++  java
  • 19-spring学习-springMVC环境配置

    新建一共环境,添加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的处理,那么也就证明了,在开发中,过滤器可以实现所有验证操作。

      

  • 相关阅读:
    需要了解的项目
    vmware安装问题:Microsoft Runtime DLL安装程序未能完成安装
    rabbitmqctl 报错
    RabbitMQ快速入门python教程
    RabbitMQ消息队基本概念
    Windows RabbitMQ 添加用户、设置角色和权限 (包含无法添加的错误处理)
    转:Window10下RabbitMQ安装图文教程
    Windows下RabbitMQ安装及入门
    crontab 详细用法 定时任务
    转 RabbitMQ
  • 原文地址:https://www.cnblogs.com/alsf/p/8215767.html
Copyright © 2011-2022 走看看