一、导入springMVC所需要的jar包

     下载地址:http://repo.spring.io/release/org/springframework/spring/

   

二、springMVC框架配置

  1、

1.1 常规web.xml配置

  <servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

      1.2 spring配置文件不在WebRoot/WEB-INF下创建时,web.xml 文件配置:

 <!-- spring mvc 核心servlet -->
<servlet>
<servlet-name>applicationContext</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 加载相应的xml,而不会去加载/WEB-INF/下的applicationContext.xml。 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup> </servlet>
<servlet-mapping>
<servlet-name>applicationContext</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

  2、(在WebRoot/WEB-INF下)创建spring配置文件

  注意:此配置文件名称必须为 :servletName-servlet.xml  (servletName即为web.xml中核心servlet的name),此处名称为spring-servlet.xml。 如果不在WebRoot/WEB-INF下创建,则需要在web.xml中作相应配置,否则文件找不到,此时web.xml配置参考 1.2 spring配置文件不在WebRoot/WEB-INF下创建时,web.xml 文件配置。

spring-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:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!--1 MVC注解支持 -->
<mvc:annotation-driven />
<!--2 注解扫描目录-->
<context:component-scan base-package="com.sxdx"></context:component-scan>
<!--3 处理静态文件 -->
<mvc:default-servlet-handler /> <!-- 视图解析器 -->
<!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/pages/" />
<property name="suffix" value=".jsp" />
</bean> --> </beans>

  3、创建Controller控制器(Action) 

 package com.sxdx.hello;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; @Controller
public class demo {
@RequestMapping(value="/demo1")
public String demo1(HttpServletRequest request,
HttpServletResponse response){
System.out.println("demo1===");
return "";
}
}

  4、浏览器访问 http://localhost:8080/spring01/demo1.do 后台输出demo1===

springMVC部署的更多相关文章

  1. SpringMVC 部署项目静态资源文件访问问题

    问题:采用SpringMVC 部署项目后程序加载或用浏览器访问时出现类似的警告,2011-01-19 10:52:51,646 WARN [org.springframework.web.servle ...

  2. 浅谈SpringMVC执行过程

    通过深入分析Spring源码,我们知道Spring框架包括大致六大模块, 如Web模块,数据库访问技术模块,面向切面模块,基础设施模块,核心容器模块和模块, 其中,在Spring框架的Web模块中,又 ...

  3. SpringMVC(一):简介和第一个程序

    本文是按照狂神说的教学视频学习的笔记,强力推荐,教学深入浅出一遍就懂!b站搜索狂神说或点击下面链接 https://space.bilibili.com/95256449?spm_id_from=33 ...

  4. SpringMVC笔记总结

    文章所有代码见:gitee 1.回顾MVC 1.1.什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑.数据.显示分离 ...

  5. SpringMVC-01 什么是SpringMVC

    SpringMVC-01 什么是SpringMVC 回顾MVC 1.什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑 ...

  6. Java系列教程-SpringMVC教程

    SpringMVC教程 1.SpringMVC概述 1.回顾MVC 1.什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务 ...

  7. SpringMVC学习01(什么是SpringMVC)

    1.什么是SpringMVC 1.1 回顾MVC 1.1.1 什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑.数据 ...

  8. SpringMVC配置版到注解版

    什么是springmvc? 1.1.什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑.数据.显示分离的方法来组织代码 ...

  9. SpringMVC详解及SSM框架整合项目

    SpringMVC ssm : mybatis + Spring + SpringMVC MVC三层架构 JavaSE:认真学习,老师带,入门快 JavaWeb:认真学习,老师带,入门快 SSM框架: ...

随机推荐

  1. asp.net获取当前页面源码并生成静态页面

    StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(strin ...

  2. 建立tracert路由列表的方法

    建立tracert路由列表的方法:电脑屏幕左下方 选择开始选项运行 输入 CMD在DOS命令行下输入:tracert (你的网站域名)   运行结果中如出现了“*     *     *    req ...

  3. Web Api 返回参数,实现统一标准化!

    string camelCaseObj = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.None, new JsonSer ...

  4. Tomcat 映射虚拟目录

    设置虚拟目录映射一般有两种用途: (1)把整个web应用映射到tomcat中: 如一个testapp的web应用的路径是/opt/testapp,则通过虚拟目录映射可以将其映射到tomcat(weba ...

  5. Ubuntu解决Sublime Text 2安装GBK Encoding Support插件仍然乱码

    Ubuntu 12.04 32位下,为Sublime Text 2安装Package Control: 1. 用Ctrl+~打开控制台,输入 import urllib2,os; pf='Packag ...

  6. dbms_stats.gather_table_stats与analyze table 的区别[转贴]

    Analyze StatementThe ANALYZE statement can be used to gather statistics for a specific table, index ...

  7. Android-监听sdcard状态

    public class MyService extends Service { private static final String TAG = "MyService"; Fi ...

  8. HTMLayout使用心得

    1.关闭按钮 采用CSS!提供的behavior实现窗口关闭功能,不需要在C++代码中处理关闭事件 div {      behavior: sys-ctl;      -sys-ctl-pos: c ...

  9. linux命令——磁盘管理pwd

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径(绝对路径). 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录.在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的 ...

  10. 仿windows phone风格主界面

    使用了ZAKER到最新版本,其主界面采用windows phone的风格,感觉还蛮好看的,挺喜欢的,就模仿写了一下,实现到界面截图如下: 第一版面: 第二版面: 在实现了它到九宫格菜单,还实现了背景图 ...