Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go to jsp page by hitting back button

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?

like image 436
saroj Avatar asked May 09 '12 09:05

saroj


People also ask

How to redirect page in JSP on button click?

Basically we can call the redirect pages using sendRedirect() method in the jsp on client-side request can be used within the server or outside of the server.

How to go back in JSP page?

Jsp Back Button enables the user back to the page from which they just come from. INPUT type="button" value="Back" onclick()="history.

How do I forward to next page in JSP?

To forward a request from one page to another JSP page we can use the <jsp:forward> action. This action has a page attribute where we can specify the target page of the forward action. If we want to pass parameter to another page we can include a <jsp:param> in the forward action.


1 Answers

you can also use this to go one page back

<button type="button" name="back" onclick="history.back()">back</button>
like image 61
shareef Avatar answered Nov 02 '22 10:11

shareef