Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp Post Method of the Form In JSP

Related Tutorials


 
 

Share on Google+Share on Google+

Post Method of the Form In JSP

Advertisement
This section provides you the best illustration of the post method of the form in JSP.

Post Method of the Form In JSP

     

This section provides you the best illustration of the post method of the form in JSP. The HTTP post method sends data to the server from the HTML form elements. This method does not show the value of elements of the HTML form in the query string in url. This method keeps all the data value of the HTML elements secure and safe because of not showing those in anywhere.

In this section, you will see that the following JSP program creates a form with a text box for your name field. If you click on the submit button, JSP code checks for fulfill your name field and after satisfying, it will show the entered name with the message like "Your username is: chandan." because here the username you have entered the "chandan".

There is no need to use POST method in the form. This method doesn't append the URL. This method is mostly used for the working with some sensitive data like the password regarding the username or any type of secret numbers such as credit card number. If you want to pass as parameters, POST method prevents these type of secret numbers because this method doesn't show any parameter's value in the url of the browser.

Here is the JSP code of the example:

<html>
	<head><title>Using Post Method in JSP Form.</title></head>
	<body>
		<form method="post">
			<table border="0" cellpadding="0" 
cellspacing="0">
				<tr>
					<td>Enter your name:
 </td>
					<td><input type="text"
 size="20" name="txtName" /></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><input type="submit" 
name="B1" value="Submit" /><input type="reset" name="B2" value=
"Reset" /></td>
				</tr>
			</table>
		</form>
		<%
			if(request.getParameter("txtName")
 != null){
				if(request.getParameter("txtName").
equals(""))
					out.println("<html><font 
color=red>Please enter your name.</font></html>");
				else
					out.println("Your username 
is: " + request.getParameter("txtName"));
			}
		%>
	</body>
</html>

Output for the above page:

Image after submission the form:

Download UsingPostMethod.jsp file.

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: May 24, 2009

Related Tutorials

Discuss: Post Method of the Form In JSP   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
Jamshid
June 22, 2011
Thank you

Thanks for your post. This post was very useful for me.
Luis Miguel Bravo
August 19, 2011
=D

so simple, so util, THANKS
DMCA.com