Consider a scenario in my first JSP I have one text field named "username" first user enter the name and click the submit button it will be redirect into second JSP page,
this JSP page contain two text field named "contactno",and "email id " and two submit button,named previous and next and enter the contact details and email id and click the previous button mean it will be again redirect into first JSP page, like that 3 different user enter his details
, so finally if I click the next button mean all user information will be print on the 3rd JSP page Expected Output
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);
}
}
I will bring all the textbox value in the servlet but I don't how to print the value in the result JSP page,
result JSP page should be
username | Email id | Contact No |
____________________________________________________
first user | 1@gmail.com | 111111 |
seconduser | 2@gmail.com | 222222 |
third user | 3@gmail.com | 333333 |