Form Processing in JSP

Introduction to Form Processing

Forms are the basic components that help us interact with web pages. The form processing became very easy with the help of JSP. The browser uses GET method and POST method for passing the information to the web server.

GET Method

The GET method is used to send the encoded user information appended to the page URL. Each encoded information is separated by '?' character.

GET is a default method to send information to web server. We should avoid using GET method to send sensitive information like as password etc. The GET method has only 4 bytes characters.

For example:
http://www.tutorialride.com/hello?key1=value&key2=value2

GET Method Example

<html>
    <head>
        <title>Reading data by Using GET method</title>
    </head>
<body>
    <h1>GET method</h1>
    <ul>
         <li><p><b>Name:</b>
             <%= request.getParameter("name")%>
         </p></li>
         <li><p><b>City:</b>
             <%= request.getParameter("city")%>
         </p></li>
         <li><p><b>Profession:</b>
             <%= request.getParameter("prof")%>
         </p></li>
    </ul>
</body>
</html>

POST Method

The POST method is used to send large amount of data on web server. When we want to send any sensitive data on web page, the POST method should be used as instead of sending text string in URL, it sends the encrypted message.

Example : Implementing POST method using Form

//welcome.html

<html>
    <head>
        <title>Using POST method</title>
    </head>
<body>
    <h2>Using POST method</h2>
    <form action = "welcome.jsp" method = "POST">
         Name: <input type = "text" name = "name"/>
         City: <input type = "text"  name = "city"/>
         Job:  <input type = "text" name = "job">
    <input type = "submit" value = "Submit">
    </form>
</body>
</html>

//welcome.jsp
      
<html>
    <head>
        <title>JSP page using POST method</title>
    </head>
<body>
     Name: <%= request.getParameter ("name") %>
     City: <%= request.getParameter ("city") %>
     Job: <%= request.getParameter ("job") %>
</body>
</html>