Extracting HTML form parameters Example

Extracting HTML form parameters Example

Posted in : Java Posted on : June 7, 2011 at 7:00 PM Comments : [ 0 ]

In this section we will discuss how can the html form parameter is extracted from HttpServletRequest.

Extracting HTML form parameters Example

In this section we will discuss how can the html form parameter is extracted from HttpServletRequest.

  • We will first create a html page
  • Then we will develop a java program where we will create an object of HttpServletRequest to extract the html form parameter.
  • Next edit the web.xml file.
  • Then finally run the program on server.

The following program describes that how a client enters its query and how the server responds as their query.


<title>Show UserId and Password</title>
<body bgcolor="yellow">
<center>Sign In</center>
<h3>Please Enter your information in their respective column</h3>
<form method="get" action="/bipul/servlet/ExtractHtmlForm">
<p><font color="red">Name <input type="text" name="name"></input></font></p>
<p><font color="red">UserId <input type="text" name="uid"
<p><font color="red">Password <input type="password"
name="pswrd" size="6"></font></input></p>
<p><input type="submit" value="submit"></input></p>


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ExtractHtmlForm extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String name, id, psw;
name = req.getParameter("name");
id = req.getParameter("uid");
psw = req.getParameter("pswrd");
PrintWriter pw = res.getWriter();
pw.println("<body bgcolor=red>");
pw.println("Hello " + name + "<br>");
pw.println("Your UserId is = " + id + "<br>");
pw.println("your Password is = " + psw);


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">


Output :


Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics