Go to the jsp page by clicking the back button

I have one 2 jsp pages and one Servlet. I retrieve the data from the database with the servlet and send the result to the page result.jspwhere I show the result. But I want to add Back buttonin result.jsp, by clicking Back button, I want to go to index.jsp, but the problem is that when I press the back button every time a message arrives Confirm form submissionand it annoys me, How can I avoid this Confirm form submission? perhaps this will happen because the processing is done in the 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.jspI go to another page result1.jspas shown below

In result.jspI wrote the following:

<a  href="result1.jsp.jsp?a code=<%out.println(student_name);%>"><%out.println(student_name);%></a>

By clicking the hyperlink above, I went to result1.jsp

( result1.jsp), " result.jsp", "" Confirm form submission . result1.jsp

<input type="button" value="Back" onclick="javascript:history.go(-1)">

Confirm form submission. ? result.jsp . ?

+5
8

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

, index.jsp result.jsp

<a href="index.jsp">Back</a>
+2

<button type="button" 
    name="back" 
    onclick='window.location='<your_path>/index.jsp'>back</button>
+1

, index.jsp, ?

<a href="index.jsp">Back</a>

, window.location. , . , result.jsp !

:

previous.jsp

<form method="post" action="Student">
<input type="hidden" name="back" value="previous.jsp" />
<input type="text" name="studentname"/>
<input type="submit" value="search"/>
</form>

result.jsp

out.println("<a href=\"" + request.getParameter("back") + "\">Back</a>");
+1

goBack goBack(). , "", .

 <!DOCTYPE html>
    <html>
    <head>
    <script>
    /* The back() method loads the previous URL in the history list. 
       This is the same as clicking the "Back button" in your browser.
    */
    function goBack() {
        window.history.back()
    }
    </script>
    </head>
    <body>

    <button onclick="goBack()">Go Back</button>

    <p>Notice that clicking on the Back button here will not result in any action, because there is no previous URL in the history list.</p>

    </body>
    </html>
+1

button.

<input type="button" value="Back" onclick="javascript:history.go(-1)">

history.go(-1) , , , , Confirm form submission.

!

, , , - result.jsp , index.jsp:

response.sendRedirect("result.jsp");

, , result.jsp , , - :

String action = request.getParameter(action);
if("submit".equals(action)) {
    // handle form data
    response.sendRedirect("result.jsp");
} else {
    // other code to display content of result.
}

index.jsp :

....
<form action="result.jsp?action=submit" ...>
0

Safari ( IE/Chrome/FF).

Working around represents your form using the get method. Of course, this is true only for "small" forms (max. 2048 K).

0
source

try it

<a href="${pageContext.request.contextPath}/index.jsp" class="btn btn-success">
    Back
</a> 

with bootstrap.css from here

0
source

All Articles