刚学springMVC,记录下学习过程,供以后查阅(githup源码)。

1,新建一个web工程。(其他按常规来)

如下:添加applicationContext.xml,webmvc-servlet.xml,和lib下的jar包。

2,修改web.xml:

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
   <display-name>springmvc</display-name>
   <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:/spring/applicationContext.xml</param-value>
   </context-param>
   <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
   <servlet>
       <servlet-name>webmvc</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:spring/webmvc-servlet.xml</param-value>
       </init-param>
   </servlet>
   <servlet-mapping>
       <servlet-name>webmvc</servlet-name>
       <url-pattern>/</url-pattern>
   </servlet-mapping>
   <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
 </web-app>

2,修改applicationContext.xml如下:

 <?xml version="1.0" encoding="UTF-8"?>

 <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop.xsd
             http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd">
     <!-- 排除springMVC Controller重复扫描 -->
     <context:component-scan base-package="controller">
         <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
     </context:component-scan>

 </beans>

3,修改webmvc-servlet.xml如下:

 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans.xsd
                         http://www.springframework.org/schema/context
                         http://www.springframework.org/schema/context/spring-context.xsd
                         http://www.springframework.org/schema/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
        <!-- 扫描业务组件,让spring不扫描带有@Service注解的类(留在root-context.xml中扫描@Service注解的类),防止事务失效 -->
        <mvc:annotation-driven/>
        <context:component-scan base-package="controller">
                <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
        </context:component-scan>
        <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
            <!-- 定义跳转的文件的前后缀 ,视图模式配置 -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/" />
         <property name="suffix" value=".jsp" />
        </bean>

 </beans>

4,在controller包下新建一个controller类。

核心代码如下:

 @Controller
 public class MainController {
     @RequestMapping("index")
     public Object index(){
         System.out.println("test");
         return "first";
     }

5,部署项目到tomcat,并在浏览器输入:

http://localhost:8080/springmvc/index

6,至此,springMVC全部配置完成。

springMVC第一课--配置文件的更多相关文章

  1. JAVAEE——SpringMVC第一天:介绍、入门程序、架构讲解、SpringMVC整合MyBatis、参数绑定、SpringMVC和Struts2的区别

    1. 学习计划   第一天 1.SpringMVC介绍 2.入门程序 3.SpringMVC架构讲解 a) 框架结构 b) 组件说明 4.SpringMVC整合MyBatis 5.参数绑定 a) Sp ...

  2. Magento学习第一课——目录结构介绍

    Magento学习第一课--目录结构介绍 一.Magento为何强大 Magento是在Zend框架基础上建立起来的,这点保证了代码的安全性及稳定性.选择Zend的原因有很多,但是最基本的是因为zen ...

  3. ChartControl第一课简短的控件初步设计

    WinForms Controls >Controls > Chart Control > Getting Started This document gives you a qui ...

  4. SpringMVC第一天(其他)

    SpringMVC第一天 框架课程 课程计划 参数绑定 SpringMVC默认支持的类型 简单数据类型 Pojo类型 Pojo包装类型 自定义参数绑定 SpringMVC和Struts2的区别 高级参 ...

  5. springMVC 第一章

    springMVC 第一章 一.分层结构的项目 组成方式: 表示层:页面,Servlet 业务层:业务逻辑类(service) 持久层:与数据库交互的类(dao) 程序执行的过程:表示层->se ...

  6. Elasticsearch7.X 入门学习第一课笔记----基本概念

    原文:Elasticsearch7.X 入门学习第一课笔记----基本概念 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https: ...

  7. emacs 入门第一课:Emacs里的基本概念

    Table of Contents 无聊的开场白 buffer(缓冲区) window(窗口)与frame Emacs的mode Emacs Lisp 函数function.命令command.键绑定 ...

  8. vue.js学习(第一课)

    学习资料 来自台湾小凡! vue.js是javascript的一个库,只专注于UI层面,核心价值永远是 API的简洁. 第一课: 不支持IE8. 1.声明式渲染: el元素的简称 element : ...

  9. <-0基础学python.第一课->

    初衷:我电脑里面的歌曲很久没换了,我想听一下新的歌曲,把他们下载下来听,比如某个榜单的,但是一首一首的点击下载另存为真的很恶心 所以我想有没有办法通过程序的方式来实现,结果还真的有,而且网上已经有有人 ...

随机推荐

  1. CSS(04) 定位

    布局常用的三种:标准流.定位.浮动: 1.文档流-标准流 窗体自上而下分成一行行(元素在 (X)HTML 中的位置),并在一行行中从左到右排放元素: 2.CSS 定位 Position 属性(绝对定位 ...

  2. MHA高可用+VIP 集群故障转移(已测试成功)

       服务器部署说明192.168.158.201 mha管理,mysql主服192.168.158.202 mha节点,mysql从服192.168.158.203 mha节点,mysql从服Man ...

  3. 分享一个导出Excel时页面不跳转的小技巧

    今天在点击客户档案导出的时候,发现先是打开了一个新标签,然后新标签自动关掉,弹出一个文件下载确认的窗口,点击确认后开始下载导出的Excel文件.这样的过程感觉窗口闪来闪去,而且可能会给用户带来困惑,是 ...

  4. How a non-windowed component can receive messages from Windows -- AllocateHWnd

    http://www.delphidabbler.com/articles?article=1 Why do it? Sometimes we need a non-windowed componen ...

  5. Google JavaScript 语言规范

    变量 ▶ 声明变量必须加上 var 关键字.   常量 ▶ 常量的形式如: NAMES_LIKE_THIS, 即使用大写字符, 并用下划线分隔. 你也可用 @const 标记来指明它是一个常量. 但请 ...

  6. Mysql的存储过程(以Mysql为例进行讲解)

       我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储 在数据库中,用户通过指定存 ...

  7. linux下mysql开启慢查询

    mysql中最影响速度的就是那些查询很慢的语句.这些慢的语句,可能是写的不够合理或者是大数据下多表的联合查询等等.所以我们要找出这些语句,分析原因,加以优化. 1.方法1:用命令开启慢查询 1).查看 ...

  8. 如何实现一个c/s模式的flv视频点播系统

    一.写在前面 视频点播,是一个曾经很热,现如今依然很热的一项视频服务技术.本人最近致力于研究将各种视频格式应用于点播系统中,现已研究成功FLV, F4V, MP4, TS格式的视频点播解决方案,完全支 ...

  9. Mac OS系统

    Mac OS系统 目录 概述 Mac OS系统常用操作 概述 Mac OS系统常用操作 显示或隐藏文件 在终端输入:defaults write com.apple.finder AppleShowA ...

  10. AndroidManifest.xml 详解 (四) 之uses-permission

    The <uses-permission> Element 我们现在告别<application>元素,回到<manifest>中定义的子元素,<uses-p ...