Home Jsp JSP Back Button
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JSP Back Button

Advertisement
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

<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:

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: June 10, 2009

Related Tutorials

Ask Questions?    Discuss: JSP Back Button  

Post your Comment


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

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
DMCA.com