Feedback Form Servlet Example


All the time we are accustomed to read client data with getParameter() method, most probably from HTML text fields. But, HTML FORM tag includes many GUI components like radio buttons, SELECT drop down lists, text areas etc. This Client HTML comes with rarely used FORM fields. To do with, a Student Feedback Form is designed where a Student completes his course from an institute and gives feedback of Faculty and Institute amenities.

Servlet Example

To read all the FORM fields, getParameterNames() of HttpServletRequest is used. The feedback data is read by Servlet and sent back to client in a table format.

Feedback Form

Student Name
Student E-Mail

How do you know this Institute

How do you rate the faculty Poor Good Very Good Excellent

Suggestions for the betterment of faculty and institute


  snrao1
  StudentFeedback



  snrao1
  /SF

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

public class StudentFeedback extends HttpServlet   
{
  public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException  
  {
    res.setContentType("text/html");
    PrintWriter pw = res.getWriter();

    java.util.Enumeration e = req.getParameterNames();
    pw.println("");

    while(e.hasMoreElements())
    {
      String fieldname = (String) e.nextElement();
      String value = req.getParameter(fieldname);

      if(value.length() != 0)
      {
        pw.println("");
      }
      else
      {
        pw.println("");
      }
    }
   
    pw.println("
" + fieldname + "" + value + "
" + fieldname + " Null
"); pw.close(); } }

java.util.Enumeration e = req.getParameterNames();

The getParameterNames() method of javax.serlet.ServletRequest inherited by javax.servlet.http.HttpServletRequest returns an object of Enumeration. This step is explained earlier in Get all parameters of HTML form.

HTML file when all fields are entered.


Servlet Example
Output screen of Servlet Example: Client data put in a table


Servlet Example
Output screen of Servlet Example with data tabulated

1 thought on “Feedback Form Servlet Example”

Leave a Comment

Your email address will not be published.