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

来源:互联网 发布:香奈儿淘宝旗舰店 编辑:程序博客网 时间:2024/06/06 06:30

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;@Controllerpublic 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>




原创粉丝点击