01-SpringMVC Hello,World
2016-01-21 21:20
459 查看
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.java1234"/>
<!-- 视图解析器 -->
<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>
HelloWorldController.java
package com.java1234.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", "StringMvc他大爷");
//返回到以helloWorld开头的suffix(后缀)为.jsp页面
return "helloWorld";
}
}
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>
helloword.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>
<?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.java1234"/>
<!-- 视图解析器 -->
<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>
HelloWorldController.java
package com.java1234.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", "StringMvc他大爷");
//返回到以helloWorld开头的suffix(后缀)为.jsp页面
return "helloWorld";
}
}
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>
helloword.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>
相关文章推荐
- java String 类的replace 和replaceAll 方法替换“?”号
- Mac OS安装java runtime环境
- 用java -X 命令查看JVM的配置说明:
- java包及其使用
- 【JAVA学习】单例模式的七种写法
- Spring面试题一
- java servlet 总览
- 简单的web实现
- 我在JavaWeb开发中的SSH整合步骤
- Elasticsearch中使用ik分词器 java api
- 冒泡排序java
- Java NIO使用及原理分析 (四)
- Java图片上传压缩处理
- Java快速入门【11~20待续】
- spring AOP
- java多线程之(yield)
- 【JAVA/辨析】Java 中Comparable和Comparator区别比较
- Java基础01 从HelloWorld到面向对象
- java多线程之(sleep)
- JavaSE入门学习6:Java基础语法(二)