【发布时间】:2016-10-26 01:46:55
【问题描述】:
我正在学习 SpringMVC 框架,我从here 获得了以下示例。 Java 控制器:
SessionController.java
package javabeat.net.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
@Controller
@RequestMapping("/sessiontest")
@SessionAttributes("sessionValue")
public class SessionController {
@RequestMapping(method = RequestMethod.GET)
public String getForm(@RequestParam("param") String paramVal, ModelMap map){
System.out.println("Param Value : " + paramVal);
map.addAttribute("sessionValue", "Test Object");
return "hello";
}
}
JSP 页面:
hello.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<%
String value = (String)session.getAttribute("sessionValue");
out.print(value);
%>
</body>
</html>
我正在尝试了解执行流程:
据我所知,它假定在执行流程中 URL /sessiontest?param=paramVal 将首先被命中。然后paramVal 被筛选到控制台。然后集合map 被键值对"sessionValue"/"Test Object" 丰富。然后返回"hello"。所以当hello.jsp被点击时,它会检索刚刚添加的值,并且html正文会屏蔽Test Object。
如果我的上述解释是正确的,我想知道:
1) 谁将ModelMap map 对象传递给getForm 方法?
2) 将hello 退回到无处的目的是什么?
3) JSP 中的session 对象如何与添加新键值对的ModelMap map 绑定?
【问题讨论】:
标签: html spring jsp spring-mvc web-applications