Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
How to work with POST method in jsp page 
 

This is detailed JSP code, how to use POST method instead of GET method in jsp page. GET is default method for sending the request to the server.

 

How to work with POST method in jsp page

                         

This is detailed JSP code, how to use POST method instead of GET method in jsp page. GET is default method for sending the request to the server. The difference between these two methods has been described below:

 

 

 

 

Difference between GET and POST

GET:

1. URL Changes to the submitted script name, appended with a list of each variable with the value.
2. Use only if the number of variable to be used in a form are very less.
3. Never use GET forms when asking for login ID and passwords.
4. Even hidden variables are shown as a part of the URL.
5. Web servers might complain about long URLs being submitted. A lot of times a URL 255 char or more is a problem.
POST:

1. This is the best way of submitting forms to the web server.
2. There is no limitation on the number of Variables passed from the form.
3. This is a transparent way of transmitting variables to the web server where hidden variable are always hidden!

jsp_with_post_method.jsp: Using POST method is nothing different than using GET method as request method in JSP. For this we just need to set the value 'POST' for the 'method' attribute of html 'form' element.

<HTML>
<HEAD>
    <TITLE>first page...create session</TITLE>
</HEAD>
<BODY bgcolor="#6E6E6E">
    <% String name = "ravi";
            session.setAttribute("user", name);
    %>
    // use POST  method to avoid show data in url 
    <FORM NAME="form1" ACTION="jsp_with_post_method.jsp" METHOD="POST">
        <TABLE bgcolor="#D8D8D8">
        <tr>
            <td> Enter name </td>
            <td><input type="text" name="txtName"></td>
        </tr>
        <tr>
            <td> Enter Email id </td>
            <td><input type="text" name="email"></td>
        </tr>
        <tr align="center"><td></td>
        <td><INPUT TYPE="submit" VALUE="show"></td>
    </FORM>
    
    <%
            if (request.getParameter("txtName") != null && 
			   request.getParameter("txtName") != null) {
                if (!(request.getParameter("txtName").equals("")) &&
			!(request.getParameter("txtName").equals(""))) {%>
    <tr>
        <td> Your name is </td>
        <td><%=request.getParameter("txtName")%></td>
    </tr>
    <tr>
        <td> Email id is </td>
        <td><%=request.getParameter("email")%></td>
    </tr>
    <%}
            }
    %>
    </TABLE>
</body> 
</html>

Save this code with extension .jsp in your application directory ("user" directory, in our case) in tomcat server. To run this application first start Tomcat server by click on startup.bat file in  tomcat-6.0.16/bin then open browser and type the url http://localhost:8080/user/jsp_with_post_method.jsp in address bar.

Enter name and email id in the appropriate text box and click on show button.

Download source code

                         

» View all related tutorials
Related Tags: c client request display page name cli ie ref e li spl m nt play isp cl es age me

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.