HelloWorldController.java文件

package com.su.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class HelloWorldController { @RequestMapping("/helloWorld")
public String helloWorld(Model model){
model.addAttribute("message", "HelloSpringMvc!");
return "helloWorld";
}
}

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:p="http://www.springframework.org/schema/p"
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/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 使用注解的包,包括子集 -->
<context:component-scan base-package="com.su"/> <!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"></property>
</bean> </beans>

helloWorld.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>
${message }
</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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>SpringMvc01</display-name>
<welcome-file-list>
<welcome-file>index.html</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>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

index.html文件

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="helloWorld.do">问候SpringMvc他大爷</a>
</body>
</html>

请求页面以及结果

最新文章

  1. C/C++ 中的include
  2. SQL多表合并查询结果
  3. eclipse将android项目生成apk并且给apk签名
  4. python selenium中使用ddt进行数据驱动测试
  5. yum clean all 是什么意思
  6. C语言 homework (3)
  7. 腾讯云Linux系统中启动自己安装的tomcat
  8. 2015版App推广全攻略(完整版)
  9. Python 快捷键
  10. Ubuntu14.04下搭建VPN服务
  11. 搭建nexus私服(maven)
  12. 【从零开始搭建自己的.NET Core Api框架】(三)集成轻量级ORM——SqlSugar:3.1 搭建环境
  13. sql server 2008 windows验证改为混合登陆SqlServer身份验证用户名密码
  14. Sprite(雪碧图)的应用
  15. 机器学习库--dlib
  16. PHP与.Net的区别(一)接口
  17. TF-IDF原理及使用
  18. 网络基础 02_TCP/IP模型
  19. MySQL-开发规范升级版
  20. 【转】django 与 vue 的完美结合 实现前后端的分离开发之后在整合

热门文章

  1. oracle数据库中的存储函数
  2. 广播即时通信src和des
  3. vue项目1-pizza点餐系统6-路由精讲之复用router-view
  4. JAVA中关于日期的最常见的操作
  5. mv - 移动 (改名) 文件
  6. 前端div+css
  7. windows无法安装.net framework 3.5解决方法
  8. 使用nginx配置二级域名
  9. python List 常用方法
  10. java web 增加信息课堂测试00