/**
*
*/
/**
* @author Administrator
*
*/
package com.study01.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/mvc")
public class HelloController { @RequestMapping("/hello")
public String hello(){
return "hello";
}
}

spring-mvc.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.study01"/> <!-- 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/jsp/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>

hello.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a>测试</a>
</body>
</html>

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>study01</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> <servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- 该名称需要和项目中的springmvc的配置文件一致 -->
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<!-- 该名称需要和上面定义的servlet的名称一致 -->
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

注意以下两点:

1,相关的几个包文件需要引用全

2,引用的包文件需要放在web-inf下面的lib文件夹下面

最新文章

  1. [MySQL性能优化系列]巧用索引
  2. CCS实现input和img水平对齐的方法
  3. OC 属性
  4. BugFixed
  5. 怎样在python中获取时间?
  6. 【练习】使用接口回调和handler实现数据加载到listview
  7. jsonp从服务器读取数据并且予以显示
  8. 不用安装语言包,教你将PS界面语言修改成默认语言(英语)
  9. 从lighttpd学到的代码技巧
  10. oralce中exists not exists in not in对于NULL的处理
  11. Delphi default属性
  12. sqlite3触发器的使用
  13. html结合js实现简单的树状目录
  14. Numpy
  15. 2017 ICPC/ACM 沈阳区域赛HDU6228
  16. mysql创建函数之省市区数据查询
  17. [Swift]LeetCode879. 盈利计划 | Profitable Schemes
  18. zzw原创_ipv6下环境配置防火墙及FTP处理一例
  19. Mysql 中的MVCC原理,undo日志的依赖
  20. Docker for windows 入门三(PowerShell命令使用)

热门文章

  1. Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
  2. shell 常用命令语句
  3. Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer capture input channel.
  4. STM32的CRC32 软件实现代码
  5. Linux网络编程socket选项之SO_LINGER,SO_REUSEADDR
  6. [DLX反复覆盖] hdu 3656 Fire station
  7. Vue 插件写法
  8. AngularJS路由系列(5)-- UI-Router的路由约束、Resolve属性、路由附加数据、路由进入退出事件
  9. SQL Server 2008 安装教程
  10. 通俗易懂地讲解 __block 变量