go to jsp page by hitting back button

forms, java, jsp, servlets

Solution

you can also use this to go one page back

<button type="button" name="back" onclick="history.back()">back</button>

Problem

I have `2 jsp pages and one Servlet`. I am fetching data from database by servlet and sending result to `result.jsp` page where i am displaying result. But i want to add a `Back button` in `result.jsp` , by clicking `back button` i want to go to `index.jsp`, but problem is when i am clicking back button everytime a message is coming `Confirm form submission` and it is irritating me. How can i avoid this `Confirm form submission`? perhaps it is coming as processing is done in servlet. index.jsp ``` <form method="post" action="Student"> <input type="text" name="studentname"/> <input type="submit" value="search"/> </form> ``` Student servlet ``` String student_name=request.getParameter("studentname"); -------fetching data from database------------ -------------------sending to result.jsp------ String nextJSP = "/result.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); dispatcher.forward(request,response); ``` result.jsp ``` //displaying data here <form action="index.jsp"> <input type="submit" value="back"/>// a back button is here which is going to index.jsp </form> ``` EDIT From `result.jsp` i am going to another page `result1.jsp` like below In `result.jsp` i have written the following: ``` <a href="result1.jsp.jsp?a code=<%out.println(student_name);%>"><%out.println(student_name);%></a> ``` By clicking the above hyperlink i went to `result1.jsp` I want to add a back button here(in result1.jsp) and after clicking i want to do to result.jsp, but when clicking back button i am getting `Confirm form submission` every time. I have written the following in `result1.jsp` ``` <input type="button" value="Back" onclick="javascript:history.go(-1)"> ``` Still i am getting that message `Confirm form submission`. How can i avoid this? I want to go to `result.jsp` directly with out this message. How is it possible?

Original source