Share on Google+Share on Google+

JSP Back Button

Jsp Back Button enables the user back to the page from which they just come from.

JSP Back Button


Jsp Back Button enables the user back to the page from which they just come from.

Understand with Example

The Tutorial illustrate an example from 'JSP Back Button'. To understand the example we have used two jsp pages: back Button.jsp and createBackButton.jsp. The backButton.jsp has three fields and a submit button whose action is to be performed on the createBackButton.jsp where we defined another field text area and back button. The backButton.jsp validates the form by displaying the alert message "Please enter the value", incase the user do not enter the values in specified field. The Back button retrieve the information values from the create back button and displayed in text area. The Back button takes the user back to the page they just came from. A Back button is created by

INPUT type="button" value="Back" onclick()="history.back()": The  Back button is created and takes the user back to the page from where the user came from.

On Click( ) :" " tells the browser to do the command in the quotes when the button is clicked and history.back() takes the viewer on step back in their previous jsp .

 Here is the code of backButton.jsp

function valid(){
if (( == "")||( == "")){
alert ( "Please enter the value" );;;
return false;
return true;
<form name="f" action="createBackButton.jsp" onsubmit="return valid();">
<table cols="2">
Employee Name: </td><td>
<input type="text" name="name">
<input type="text" name="company"></td></tr>
<tr><td><input type="submit" value="Next" ></td></tr>

Here is the code of createBackButton.jsp

<table cols="2">
Description: </td><td>
<textarea rows="5" cols="40" name="des">Name :&nbsp; <%=request.getParameter("name")%>
Company :&nbsp; <%=request.getParameter("company")%></textarea>
<input type=button value="Back" onCLick="history.back()">

Output will be displayed as:

On clicking the button, the action is performed and displays the following:

Download Source Code:



Posted on: June 10, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JSP Back Button  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
joshua b
February 27, 2012

i get the first one jsp back button what is the value that i need to put in, plz help call me @ 859-421-7366, if i don't pick up leave a voicemail, i dnt answer numbrs i dnt hnw, u will have a bttr chnce of reaching me by phone