您的位置:首页 > 编程语言 > Java开发

JAVA SPRING MVC 实现一个简单的页面显示功能

2011-07-07 18:21 1091 查看
1.首先在src/main/src中建立controller文件
package com.aaa.bbb;

import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TestController {
@RequestMapping("/*/test")
public String ccc(HttpServletRequest request,Model model)
{
model.addAttribute("ddd","Hello china");
return "ccc";

}

}

2.在src/main/webapp/...../view中建立视图view(ccc)<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1><%=request.getAttribute("ddd") %></h1>
</body>
</html>附录:在web.xml可以定义欢迎页,运行后默认显示的页面
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring java mvc html string class
相关文章推荐