在我的第一个JSP中考虑一个场景我有一个名为&#34的文本字段;用户名"第一个用户输入名称并单击提交按钮,它将重定向到第二个JSP页面,
这个JSP页面包含两个文本字段,名为" contactno"和" email id"和两个提交按钮,名为上一个和下一个并输入联系人详细信息和电子邮件ID并单击上一个按钮意味着它将再次重定向到第一个JSP页面,就像3个不同的用户输入他的详细信息
,最后如果我点击下一个按钮意味着所有用户信息将在第3个JSP页面上打印 预期产出
username | Email id | Contact No |
__________________________________________|
x | 1@gmail.com | 111111 |
y | 2@gmail.com | 222222 |
z | 3@gmail.com | 333333 |
的index.jsp
<form action="profile.jsp" method="post">
user name <input type="text" name="username"> </br>
<input type="submit" value="submit"></br>
</form>
profile.jsp
<form action="UserController" method="post">
Phone Number <input type="text" name="phoneno"> <br>
Email_id <input type="text" name="emailid"> <br>
<input type="hidden" name="username" value="<%= request.getParameter("username") %>">
<input type="submit" name="button1" value="next">
<input type="submit" name="button1" value="previous">
</form>
UserController.java(servlet的)
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String button = request.getParameter("button1");
String phoneno = request.getParameter("phoneno");
String emailid = request.getParameter("emailid");
String uname = request.getParameter("username");
User user = new User();
user.setUname(uname);
user.setMail(mail);
user.setContactno(contactno);
ArrayList<User> al = new ArrayList<User>();
al.add(user);
request.setAttribute("info", al);
if (button.equals("Next")) {
RequestDispatcher rd = request.getRequestDispatcher("result.jsp");
request.setAttribute("userinfo", al);
rd.forward(request, response);
} else if (button.equals("Previous")) {
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
}
}
我将带来servlet中的所有文本框值,但我不知道如何在结果JSP页面中打印该值,
结果JSP页面应该是
username | Email id | Contact No |
____________________________________________________
first user | 1@gmail.com | 111111 |
seconduser | 2@gmail.com | 222222 |
third user | 3@gmail.com | 333333 |