[英]Printing JSP form data on another JSP page
I have a jsp form that takes different inputs from user. 我有一个jsp表单,它接受用户的不同输入。 How can I print the submitted data on another jsp page?
如何在另一个jsp页面上打印提交的数据?
In your first JSP page: 在您的第一个JSP页面中:
<form method="post" action="otherPage.jsp">
<input type="text" name="firstName">
<input type="submit" value="Submit">
</form>
then on the otherPage.jsp
you can get the value of the input: 然后在
otherPage.jsp
上,您可以获取输入的值:
<%
String name = request.getParameter("firstName");
out.println("Firstname: " + name);
%>
..although using scriptlets is normally discouraged. ..尽管通常不鼓励使用scriptlet。
If you want to use eg Spring MVC you post the form to a Controller
which handles the request and there you can pass the parameters forward. 如果要使用例如Spring MVC,则可以将表单发布到处理请求的
Controller
,然后可以将参数转发。
The use of scriptlets in JSP is strongly discouraged: 强烈建议不要在JSP中使用scriptlet:
How to avoid Java code in JSP files? 如何避免JSP文件中的Java代码?
You can achieve the same using JSP Expression Language (JSP EL): 您可以使用JSP表达式语言(JSP EL)实现相同的目的:
<p>First name was ${param.firstName}</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.