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

        

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

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

Here is the code of createBackButton.jsp

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

Output will be displayed as:

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

Download Source Code: