【发布时间】:2014-10-31 09:31:10
【问题描述】:
在我的一个 JSP 中,我让用户输入一些关于他们自己的详细信息。当他们单击提交时,我希望它重定向到的页面记住变量,然后将其打印出来。
例如
(register.jsp) Username: Barney
(welcome.jsp) Welcome Barney
(register.jsp) Username: Vernon
(welcome.jsp) Hello Vernon
当前代码:
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(ModelMap map, HttpSession session,
@RequestParam(value="givenUser") String givenUser) {
session.setAttribute("ans", givenUser);
map.addAttribute("displayAnswer", givenUser);
map.put("givenUser", givenUser);
return "register";
}
}
欢迎请求映射:
@RequestMapping(value = "/welcome", method = RequestMethod.GET)
public String welcome() {
return "welcome";
}
然后在welcome.jsp 我有:你好${givenAnswer}
register.jsp,一旦点击里面的链接,就会转到welcome.jsp
这是 register.jsp
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page isELIgnored="false" %>
<html>
<head>
<title>SPRING ####### WEB</title>
</head>
<body>
<h2>SUCCESSFUL REDIRECTION!!!</h2>
<p>Register</p>
<form action="/HelloSpring/welcome" method="post">
Username: <input type="text" name="givenUser" >
Firstname: <input type="text" name="givenPassword">
Surname: <input type="text" name="givenSurname" >
Password: <input type="password" name="givenPassword">
<input type="submit" value="Submit">
</form>
</body>
</html>
welcome.jsp
<%@taglib uri="http://www.springframework.org/tags/form" prefix="spring"%>
<%@ page isELIgnored="false" %>
<html>
<head>
<title>SPRING ####### WEB</title>
</head>
<body>
<h2>Spring Page Redirection</h2>
<p>Welcome ${givenUser}, your password is ${givenPassword}</p>
</body>
</html>
所以我的问题是我没有包括什么,因为它目前只是在用户提交详细信息时触发一个空白
【问题讨论】:
-
欢迎使用 stackoverflow :) 那么到目前为止您尝试了什么?阅读How to Ask
-
很高兴你能感觉到 ${status.value}!
-
是否打印任何内容。用您的弹簧控制器代码编辑问题?
-
您想要的是 3 个元素之间的迭代:JSP 中的表单、控制器和第二个 JSP。您展示了控制器,但由于我的水晶球目前无法使用,您至少可以展示一下表格吗?
-
你想看什么?控制器已经显示在我的代码中。你想要 answer.jsp 里面的表格吗?
标签: java spring jsp variables spring-mvc