1、导包

Spring所有包

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" 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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springServlet.xml</param-value>
</context-param> <servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

3、springServlet.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: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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!-- scan the package and the sub package -->
<context:component-scan base-package="com.sysker"/> <!-- don't handle the static resource -->
<mvc:default-servlet-handler /> <!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven /> <!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/view/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>

4、servlet文件

package com.sysker.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/spring")
public class SpringServlet {
@RequestMapping("/index")
public String index() {
return "index";
}
}

第一个spring MVC的更多相关文章

  1. 第一个Spring MVC程序

    最近公司项目要开始使用Spring MVC替代Struts2了,就学习了一下Spring MVC的使用.这是第一个Spring mvc程序,分别使用xml和注解两种方式. 一.使用xml格式进行构建 ...

  2. 干净win7要做几步才能运行第一个Spring MVC 写的动态web程序

    干净win7要做几步才能运行第一个Spring MVC 写的动态web程序: 1. 下载安装jdk 2. 配置Java环境变量 3. 测试一下第1,2两步是否完全成功:http://jingyan.b ...

  3. Spring学习之第一个Spring MVC程序(IDEA开发环境)

    回顾Java平台上Web开发历程来看,从Servlet出现开始,到JSP繁盛一时,然后是Servlet+JSP时代,最后演化为现在Web开发框架盛行的时代.一般接触到一个新的Web框架,都会想问这个框 ...

  4. 使用Maven创建一个Spring MVC Web 项目

    使用Maven创建java web 项目(Spring MVC)用到如下工具: 1.Maven 3.2 2.IntelliJ IDEA 13 3.JDK 1.7 4.Spring 4.1.1 rele ...

  5. 编写第一个spring MVC程序

    一.下载和安装spring框架 进入http://repo.springsource.org/libs-release-local/org/springframework/spring/4.2.0.R ...

  6. 在web项目中搭建一个spring mvc + spring + mybatis的环境

    介绍:本文中示范搭建一个ssm环境的框架:使用流程就是客户端通过http请求访问指定的接口,然后由服务器接受到请求处理完成后将结果返回. 本项目请求流程细节介绍:由客户端请求到指定的接口,这个接口是个 ...

  7. 快速创建一个 spring mvc 示例

    1. 创建一个 servlet 项目 参考 http://www.cnblogs.com/zno2/p/5908589.html 2. 引入 spring mvc 依赖 <dependency& ...

  8. 在Mac系统下用STS搭建一个Spring MVC项目

    [本文出自天外归云的博客园] 从STS的下载到空项目的搭建 1. 下载STS,下载解压缩后点击sts-bundle文件夹中的STS文件启动ide: 2. 创建Spring MVC项目:File-> ...

  9. 利用maven构建一个spring mvc的helloworld实例

    刚开始学习maven和spring mvc,学的云里雾里的 这里提供一个hello world实例,记录自己的学习之路 首先看maven官网的介绍 Apache Maven is a software ...

  10. 一个spring mvc 需要用到到文件

    一. 类 org.springframework.stereotype.Controller; org.springframework.web.bind.annotation.RequestMappi ...

随机推荐

  1. openTSDB+HBase+ZK遇到的坑汇总

    1.zookeeper返回的hbase地址是hostname,外网如何访问? 如果需要直接访问zk获取hbase地址进而访问,目前需要本机配置host ip  hostname 如果是要长期解决方法, ...

  2. 技术总监Sycx的故事

    其实我在各种演讲里,线下吹牛里面无数次提及过他,讲过他的故事,但是总还是没有任何一次认认真真的详细讲过,所以,今天就讲讲他的故事吧. Sycx是福建漳州人,我经常开玩笑说,你生于一个著名的骗子之乡,为 ...

  3. hihoCoder#1122(二分图最大匹配之匈牙利算法)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上一回我们已经将所有有问题的相亲情况表剔除了,那么接下来要做的就是安排相亲了.因为过年时间并不是很长,所以姑姑希望能够尽可 ...

  4. PV 和 UV IP

    PV(page view),即页面浏览量,或点击量;通常是衡量一个网络新闻频道或网站甚至一条网络新闻的主要指标. 高手对pv的解释是,一个访问者在24小时(0点到24点)内到底看了你网站几个页面.这里 ...

  5. HTML5一些元素的整理

    address元素: 定义和用法 <address> 标签定义文档或文章的作者/拥有者的联系信息. 如果 <address> 元素位于 <body> 元素内,则它表 ...

  6. CountDownLatch的介绍和使用

    1.类介绍 java.util.concurrent 类 CountDownLatch java.lang.Object java.util.concurrent.CountDownLatch 一个同 ...

  7. 【转】onclick事件与href='javascript:function()'的区别

    href='javascript:function()'和onclick能起到同样的效果,一般来说,如果要调用脚本还是在onclick事件里面写代码,而不推荐在href='javascript:fun ...

  8. Mybatis 内置 Java 类型别名与 typeHandlers

    aliases There are many built-in type aliases for common Java types. They are all case insensitive, n ...

  9. JAVA基础知识总结8(设计模式)

    设计模式:JAVA中有23种设计模式 1.解决问题最行之有效的思想. 2.是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 3.使用设计模式是为了可重用代码.让代码更容易被他人理解 ...

  10. Python 面向对象 (进阶篇)

    <Python 面向对象(初级篇)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使用(可 ...