【发布时间】:2015-09-18 03:17:08
【问题描述】:
我想创建 2 个 JSP 页面。我有控制器:
@Controller
@RequestMapping(value = "/api/web/users")
public class ServletWebController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "message");
return "hello";
}
}
它打开第一个带有表单的 JSP 页面:
<html>
<body>
<form action="main.jsp" method="post">
First Name: <input type="text" name="first_name">
<br />
Last Name: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
当我在表单中输入数据并按下提交按钮时,我想打开第二个 JSP 页面并从表单中打印数据:
<html>
<head>
<title>Using GET and POST Method to Read Form Data</title>
</head>
<body>
<center>
<h1>Using GET Method to Read Form Data</h1>
<ul>
<li><p><b>First Name:</b>
<%= request.getParameter("first_name")%>
</p></li>
<li><p><b>Last Name:</b>
<%= request.getParameter("last_name")%>
</p></li>
</ul>
</body>
</html>
但是第二个 JSP 页面没有打开。所以我输入http://localhost:4000/api/web/users 我有表格。然后我输入数据并按“提交”。然后我有这个链接http://localhost:4000/api/web/main.jsp 和错误:
HTTP Status 404 - /api/web/main.jsp
type Status report
message /api/web/main.jsp
description The requested resource is not available.
Apache Tomcat/8.0.26
我是 Spring 和 JSP 的新手,如何从另一个 JSP 打开 JSP?
【问题讨论】:
-
较新的jsp路径是什么?是 hello.jsp 吗?
标签: java jsp spring-mvc