?
Solved

Dynamic forms

Posted on 2005-04-24
10
Medium Priority
?
371 Views
Last Modified: 2013-01-04
I'm trying to create a dynamic form using JSP, servlet, etc.  When I say dynamic, for example I have 15 different forms with different questions that will display depending on which type a questions is selected on the page before the form page.  What I'm trying to do is have one jsp for these 10 forms instead of creating 10 pages with different form content.  I have all the questions in my database and can display one set of questions on a jsp but trying to figure out how to display the text area, text field, list/menu box next to the questions that need one of these form entries.  I started out trying to use a java string buffer but haven't been successful.  Can somebody give me some answers on how to construct this project?  I've searched on the web for an example but no luck.  If you know of a tutorial or a book that gives step by step instructions please let me know.  Thank You.

0
Comment
Question by:javabeginr
  • 5
  • 4
10 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13857607
Can you post some of your code?

I'm not 100% sure what your problem is :-(
0
 

Author Comment

by:javabeginr
ID: 13871055
First should I use a string buffer to accomplish what I'm trying to do?  The problem is I'm not sure how to do what I'm trying to do (displaying questions and a text box dynamically).  What I need is somebody who has actually done this before and can show me, so I can understand what's happening.  Again can somebody show me or direct me to a website or a book that explains = displaying form content dynamically.  

0
 
LVL 9

Expert Comment

by:doronb
ID: 13873497
I always start with a static form which I edit in HTML first.
Once I have the HTML form built as a static file, I then create a template from the HTML.
Once I have built several templates (from all the forms I need to create) I identify template parts that appear in more than just one form.
I then create Servlet code (or JSP tags) that output the template parts I've previously identified.

When I work with Servlets, I usually have some sort of generic Tag-based class that I can use as follows:

      //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            HtmlWriter out = new HtmlWriter(response);
            //The size of the client's visible area within a Web Browser
            Dimension clientSize = ServletUtils.getDimension("clientSize", request);
            String pageName = (clientSize == null) ? "IdeBoot" : "Ide Main";
            out.html("Project Ghost [ " + pageName + " ]");
            out.setBodyAttribute("bgcolor", "#300303");
            out.setBodyAttribute("style", "margin:0px;border:none;");
            if (clientSize == null) {
                  out.openTag("table");
                  out.addTagAttribute("border", "0");
                  out.addTagAttribute("height", "100%");
                  out.addTagAttribute("width", "100%");
                  out.openTag("tr");
                  out.addTagAttribute("height", "1%");
                  out.openTag("td");
                  out.addTagAttribute("width", "1%");
                  addApplet(false, out, 5, 5, "left", 0);
                  out.closeTag("tr");
                  out.emptyTag("td");
                  out.emptyTag("td");
                  out.closeTag("table");
                  out.openTag("tr");
                  out.addTagAttribute("height", "98%");
                  out.openTag("td");
                  out.addTagAttribute("width", "100%");
                  out.addTagAttribute("colSpan", "3");
                  out.openTag("p");
                  out.addTagAttribute("align", "center");
                  addApplet(false, out, 600, 26, "middle", -1);
                  out.closeTag("table");
                  out.openTag("tr");
                  out.addTagAttribute("height", "1%");
                  out.emptyTag("td");
                  out.emptyTag("td");
                  out.openTag("td");
                  out.addTagAttribute("width", "1%");
                  addApplet(false, out, 5, 5, "right", 1);
            } else {
                  addApplet(true, out, clientSize.width, clientSize.height, "middle", -1);
            }
            out.output();
      }

As you can see, my HtmlWriter actually *knows* how to create, open and close tags, building them into a tag-tree and making sure they all close properly.  Then, once I'm done adding tags to my HtmlWriter, I simply call its output() method to write everything through the HttpServletResponse instance.

Good luck and I hope this helps,
Doron
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:javabeginr
ID: 13891561
Well thanks for this but I would rather not use swing.  I'm still focused on using StringBuffer or PrintWriter.  It looks like I'm not going into enough detail so I'll explain some more.  If I have a jsp called DropDown.jsp that contains a drop down menu/list like the example below


<html>
<head>
</head>
<body>
<form name="form" method="post" action="">
  <select name="select">
    <option>Form 1</option>
    <option>Form 2</option>
    <option>Form 3</option>
  </select>
</form>
</body>
</html>



If I select form 1, form 2, or form 3 a method in my servlet will display the content of the form you pick on say a jsp called AllForms.  The method in my servlet will be something like this

buf.append("<html>");
buf.append("<head>");
buf.append("<title>Form 1</title>");
buf.append("</head>");
buf.append("<body>");
buf.append("<form name="form1" method="post" action="">");
buf.append("<table">");
buf.append("<tr>");
buf.append("<td>Name:</td>");
buf.append("<td><input type="text" name="textfield"></td>");
buf.append("</tr>");
buf.append("</body>");
buf.append("</html>");

I'll use a return to the AllForms.jsp


Say the Form 2's method is different and something like this


buf.append("<html>");
buf.append("<head>");
buf.append("<title>Form 2</title>");
buf.append("</head>");
buf.append("<body>");
buf.append("<form name="form2" method="post" action="">");
buf.append("<table">");
buf.append("<tr>");
buf.append("<td>Color:</td>");
buf.append("<td><select name="select">
    <option>Blue</option>
   <option>Red</option>
      </select></td>");
buf.append("</tr>");
buf.append("</body>");
buf.append("</html>");


Of course my forms are a lot more intense with sometimes more than 10 questions depending on which form is selected  and the form fields will have text fields, text area, radio button, checkbox but each form will have different questions but have the same form fields.  My question what is the most productive way of doing this?  Can somebody give me an example of how I can loop through this and display the contents on a jsp using a method using string buffer?




0
 
LVL 9

Expert Comment

by:doronb
ID: 13892210
Who said anything about using Swing?!!?!?  The code I posted does not use Swing.  My HtmlWriter is a special helper class I wrote that wraps a PrintWriter over the HttpServletResponse.

I don't use JSP as I find it easier to completely program the HTML output myself, but I think that what you are looking for is actually defining your own Tag Library so that you can use them in your JSP forms.  However, if I'm not mistaken, the sample you've attached is not from a JSP but rather a Servlet since a JSP doesn't requite adding the HTML/TITLE/BODY tags to be embedded in a StringBuffer.

Here is a JSP taglib tutorial presented by Sun: [ http://java.sun.com/products/jsp/tutorial/TagLibrariesTOC.html ]

In conclusion, if you're looking for the JSP solution, read up on creating Tag Libraries where your customized tags can render dynamic content based on parameters you send through JSP taglib-syntax.  If on the other hand, you're looking for a Servlet solution, then working with a StringBuffer and PrintWriter over the HttpServletResponse instance would be the way to go.  If you want some code samples for that, I can post more code to demonstrate the process.
0
 
LVL 9

Accepted Solution

by:
doronb earned 2000 total points
ID: 13892235
Just a simple Servlet Questionnaire I've written long ago, it displayes a Questionnaire, processes the user input then displays the results to the user:

//_____________________
// Servlet Source Code
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
package dev.webaccess;

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

public class QuestionnaireServlet extends HttpServlet {
      // The type of reply we are going to send to the server..
      private static final String CONTENT_TYPE = "text/html";
      // Marker for where the questions start..
      private static final String MARKER_QUESTIONS = "[questions]";
      // Marker for where the answers start..
      private static final String MARKER_ANSWERS = "[answers]";
      // Marker for the Cookie's UserName field..
      private static final String COOKIE_USERNAME = "UserName";
      // Question's FileName..
      private static final String FILE_QUESTION = "question.d";
      // Answers's FileName..
      private static final String FILE_ANSWERS = "ansewrs.d";
      // A Vector object to hold the Questions..
      private static final Vector vQuestions = new Vector();
      // A Vector object to hold the Answers..
      private static final Vector vAnswers = new Vector();
      // Properties object to hold the results..
      private static final Properties prpResults = new Properties();
      // A PrintWriter object used to output our Servlet reply..
      private PrintWriter out;
      // The Users Name..
      private String userName;
      // The Users Name as it was entered in the Form..
      private String formUserName;
      // The form target, i.e. the path to this Servlet itself..
      private String formTarget;
      // The User's answer map, an array with a slot for each question..
      private int[] answerMap;
      // Boolean flag that tells us if the Form is missing some answers..
      private boolean missingAnswers;

      // Initialize Questions and Answers Cache..
      public void init() throws ServletException {
            Vector collector = null;
            // Read the question's file..
            File questionFile = new File(getServletContext().getRealPath(FILE_QUESTION));
            try {
                  FileReader fr = new FileReader(questionFile);
                  BufferedReader br = new BufferedReader(fr);
                  // Read through the file, line by line..
                  for (String line = br.readLine(); line != null; line = br.readLine()) {
                        // Does this line mark the start of the Questions?
                        if (line.equals(MARKER_QUESTIONS)) {
                              collector = vQuestions;
                              // Does this line mark the start of the Answers?
                        } else if (line.equals(MARKER_ANSWERS)) {
                              collector = vAnswers;
                              // Are we collecting either Questions or Answers?
                        } else if (collector != null) {
                              // Collect the next line as either Question or Answer..
                              collector.addElement(line);
                        }
                  }
            } catch (IOException ex) {
                  ex.printStackTrace();
            }
            File answerFile = new File(getServletContext().getRealPath(FILE_ANSWERS));
            if (answerFile.exists()) {
                  try {
                        FileInputStream fis = new FileInputStream(answerFile);
                        prpResults.load(fis);
                        fis.close();
                        fis = null;
                  } catch (IOException ex) {
                        ex.printStackTrace();
                  }
            }
      }

      // Clean up resources
      public void destroy() {
            vQuestions.clear();
            vAnswers.clear();
      }

      private void processException(Exception ex) {
            // Output the Java Exception inside a TextArea HTML object..
            out.println("<TEXTAREA>");
            ex.printStackTrace(out);
            out.println("</TEXTAREA>");
      }

      private void readUserNameFromCookies(Cookie[] cookieList) {
            // Assume we don't know the current user..
            userName = null;
            // Did we get any cookies at all?
            if (cookieList != null && cookieList.length > 0) {
                  // Go through all the Cookies..
                  for (int i = 0; i < cookieList.length; i++) {
                        // Does this Cookie have the name of the User taking this Questionnaire?
                        if (COOKIE_USERNAME.equals(cookieList[i].getName())) {
                              // Get the Cookie's value..
                              userName = cookieList[i].getValue();
                              // Have we found the User has already taken this Questionnaire?
                              if (userName != null && !userName.equals("*")) {
                                    // No need to search in any other Cookies..
                                    break;
                              }
                        }
                  }
            }
      }

      private void processRequestInput(HttpServletRequest request) {
            // Assume the User will complete the Form..
            missingAnswers = false;
            // Read the Cookie list sent from the Client..
            Cookie[] cookieList = request.getCookies();
            // Try and get the User name from the Cookie list..
            readUserNameFromCookies(cookieList);
            // Get the future form target from the Request..
            formTarget = request.getServletPath();
            // Initialize the AnswerMap..
            answerMap = new int[vQuestions.size()];
            // Read the Request parameters into the AnswerMap..
            for (int i = 0; i < answerMap.length; i++) {
                  // Assume we do not have an Answer yet for this Question..
                  answerMap[i] = -1;
                  // Read the Question's Answer..
                  String param = request.getParameter("Q" + i);
                  // Do we have an answer at all?
                  if (param != null && param.startsWith("A")) {
                        // Parse the answer and put it in the right AnswerMap slot..
                        answerMap[i] = Integer.parseInt(param.substring(1));
                  } else {
                        missingAnswers = true;
                  }
            }
            // Now, read the User Name from the Form itself..
            formUserName = request.getParameter("userName");
            // Do we have a valid User name at all?!
            if (formUserName == null || formUserName.equals("")) {
                  // Forget the UserName sent to us..
                  formUserName = null;
                  // Mark the answers as missing..
                  missingAnswers = true;
            }
      }

      private void prepareResponse(HttpServletResponse response) throws IOException {
            // Set the response type for the Browser on the Client's end..
            response.setContentType(CONTENT_TYPE);
            // Get the PrintWriter object from the Response object..
            out = response.getWriter();
            // Output a proper HTML header..
            out.println("<HTML><HEAD><TITLE>QuestionnaireServlet</TITLE></HEAD>");
            // Make the background colour white..
            out.println("<BODY bgcolor=\"#ffffff\">");
            // Add the Header of the HTML page..
            out.println("<H1>Course Questionnaire</H1>");
            // Are we missing any answers?
            if (!missingAnswers) {
                  // Since we're not missing any results, create the cookie..
                  Cookie c = new Cookie(COOKIE_USERNAME, formUserName);
                  // We want the Cookie to stay "fresh" for as long as possible..
                  c.setMaxAge(Integer.MAX_VALUE);
                  // Add the cookie to the Response..
                  response.addCookie(c);
            }
      }

      private void displayQuestion(int questionIndex, String question) {
            // Put the question in the table..
            out.println("<TD valign=\"TOP\"><U>Question #" + (questionIndex + 1) + "</U><BR><H2><I><B>" + question + "</B></I></H2></TD>");
      }

      private void displayAnswers(int questionIndex) {
            String selected = null;
            // First answer's index is 0..
            int answerIndex = 0;
            // Create a Table Cell for the answers..
            out.println("<TD valign=\"TOP\" width=\"25%\"><P>");
            // Get an Enumeration of all the possible ansewrs..
            Enumeration enum = vAnswers.elements();
            // Go through all possible ansewrs..
            while (enum.hasMoreElements()) {
                  // Check if we have a valid AnswerMap slot for this question?
                  if (answerMap != null && questionIndex < answerMap.length) {
                        // If the Answer was already selected by the User, remember it for next time the Form is displayed..
                        selected = answerMap[questionIndex] == answerIndex ? " checked " : " ";
                  }
                  // Put the ansewr in the Table as an INPUT field for the Form..
                  out.println("<INPUT" + selected + "type=\"radio\" name=\"Q" + questionIndex + "\" value=\"A" + answerIndex + "\">" + enum.nextElement() +
                        "</INPUT>");
                  // Do we have more answers to display?
                  if (enum.hasMoreElements()) {
                        // Then add an HTML-Break and increase the answer's Index..
                        out.println("<BR>");
                        answerIndex++;
                  }
            }
            // We're done displaying the answers, close the Table Cell..
            out.println("<BR>&nbsp;<BR></P></TD>");
      }

      private void displayQuestionnaireForm() {
            // Create the Form..
            out.println("<FORM action=\"" + formTarget + "\" method=\"post\">");
            // Ask for the User's name..
            out.print("<P>Please enter your name: <INPUT type=\"text\" name=\"userName\"");
            // Do we know what the User's name was last time the Form was posted?
            if (formUserName != null) {
                  // Add the User's Name so he/she doesn't have to re-type it..
                  out.print(" value=\"" + formUserName + "\"");
            }
            out.println("></P>");
            // Ask the user to answer the questions..
            out.println("<P>Please read the statements and respond to each one:</P>");
            // Add the Questions and their Answers in an HTML Table..
            out.println("<TABLE border>");
            // Start from Question #1, which index is actually 0..
            int questionIndex = 0;
            // Start with the darker background
            boolean dark = true;
            // Get an Enumeration of the questions..
            Enumeration enum = vQuestions.elements();
            // Go through all the questions..
            while (enum.hasMoreElements()) {
                  // Start a new HTML-Row for the current Question..
                  out.print("<TR style=\"background:#");
                  // Add the row's colour..
                  out.print(dark ? "A0A0A0" : "C0C0C0");
                  // Close the TR tag..
                  out.println("\">");
                  // Display the next question..
                  displayQuestion(questionIndex, enum.nextElement().toString());
                  // Display all possible answers..
                  displayAnswers(questionIndex);
                  // Close the Question's Row..
                  out.println("</TR>");
                  // Do we have more Questions to display?
                  if (enum.hasMoreElements()) {
                        // Change the colour for the next Question's Row..
                        dark = !dark;
                        // Increase the Question's index..
                        questionIndex++;
                  }
            }
            // Close the TABLE tag..
            out.println("</TABLE>");
            // Add the Form's Submit/Reset buttons..
            out.println("<P>Press Submit to answer the Questionnaire.</p>");
            out.println("<P><INPUT type=\"submit\" name=\"Submit\" value=\"Submit\">");
            out.println("<INPUT type=\"reset\" value=\"Reset\"></P>");
            out.println("</FORM>");
      }

      private void processResponse() {
            // Do we have all the answers?
            if (missingAnswers) {
                  // Is the User's name missing?
                  if (formUserName == null) {
                        // Inform the User with need his/her name..
                        out.println("<P>You must enter your User Name!</p>");
                  } else {
                        // Inform the User with need ALL the questions answered..
                        out.println("<P>Please answer all the questions before submitting the form!</p>");
                  }
                  // Display the Questionnaire again so the user can fill it..
                  displayQuestionnaireForm();
            } else {
                  StringTokenizer stResults = null;
                  // Go through all the answers given by the user..
                  for (int i = 0; i < answerMap.length; i++) {
                        // Get the answer result's saved for this Question..
                        String answer = prpResults.getProperty("Q" + i, null);
                        // Create an empty StringBuffer to hold the results..
                        StringBuffer answerBuild = new StringBuffer();
                        // Did we save Results for this Question already?
                        if (answer == null) {
                              // Go through all the answers..
                              for (int z = 0; z < vAnswers.size(); z++) {
                                    // If we're on the right answer, add a 1, otherwise, add a 0..
                                    answerBuild.append(z == answerMap[i] ? '1' : '0');
                                    // Add the delimeter..
                                    answerBuild.append('/');
                              }
                              // Store the result String in the Answer variable..
                              answer = answerBuild.toString();
                        } else {
                              // Break the results into tokens..
                              stResults = new StringTokenizer(answer, "/");
                              // Start counting the tokens..
                              int z = 0;
                              // Go through all the tokens..
                              while (stResults.hasMoreTokens()) {
                                    // Are we on the right answer?
                                    if (z == answerMap[i]) {
                                          // Convert former result to an int, add 1 and store in StringBuffer..
                                          answerBuild.append(String.valueOf(Integer.parseInt(stResults.nextToken()) + 1));
                                    } else {
                                          // Just add the same result to the StringBuffer..
                                          answerBuild.append(stResults.nextToken());
                                    }
                                    // Add the delimeter..
                                    answerBuild.append('/');
                                    // Move over the AnswerMap..
                                    z++;
                              }
                              // Store the result String in the Answer variable..
                              answer = answerBuild.toString();
                        }
                        // We've now dealt with the Question, store the modified result and move to the next Question..
                        prpResults.setProperty("Q" + i, answer);
                  }
                  // Create the File object pointing to the Results file..
                  File answerFile = new File(getServletContext().getRealPath(FILE_ANSWERS));
                  try {
                        // Create a FileOutputStream to save the Properties Result object into..
                        FileOutputStream fos = new FileOutputStream(answerFile);
                        // Save the properties..
                        prpResults.store(fos, "Questionnaire Results");
                        // Flush, close and forget the FileOutputStream..
                        fos.flush();
                        fos.close();
                        fos = null;
                  } catch (IOException ex) {
                        // Show the Exception
                        processException(ex);
                  }
                  out.println("<P>Your input has been accepted and recorded.</p>");
                  out.println("<P>Please click <A href=\"" + formTarget + "\">here</A> if you wish to view the results.</p>");
            }
      }

      private double roundUp(double amt) {
            DecimalFormat df = new DecimalFormat("#######0.00");
            return Double.valueOf(df.format(amt)).doubleValue();
      }

      private void displayResults(int questionIndex) {
            // The next token to use..
            double[] resultMap = new double[vAnswers.size()];
            // Get the results for the next question..
            String answer = prpResults.getProperty("Q" + questionIndex, null);
            // Break the results into tokens..
            StringTokenizer stResults = new StringTokenizer(answer, "/");
            // Start with a zero total for this question..
            double resultTotal = 0;
            // First answer's index is 0..
            int answerIndex = 0;
            // Go through all the answers for this question..
            while (stResults.hasMoreTokens()) {
                  // Get the result for answer x, for this Question..
                  resultMap[answerIndex] = Integer.parseInt(stResults.nextToken());
                  // Add the result to the total..
                  resultTotal += resultMap[answerIndex];
                  // Advance the answer index..
                  answerIndex++;
            }
            double resultPercentage = 0.0;
            // Go through all the results..
            for (int i = 0; i < resultMap.length; i++) {
                  // Calculate the percentage and put it in the ResultMap..
                  resultMap[i] = resultMap[i] * 100 / resultTotal;
                  // Add the results..
                  resultPercentage += resultMap[i];
            }
            // Calculate and distribute the difference of rounding up all the percentage data..
            double diff = (100.0 - resultPercentage) / resultMap.length;
            // Did we find a calculated difference?
            if (diff != 0.0) {
                  // Go through all the results and add the difference to them..
                  for (int i = 0; i < resultMap.length; i++) {
                        // Calculate the percentage and put it in the ResultMap..
                        resultMap[i] += diff;
                  }
            }
            // Start from zero, again..
            answerIndex = 0;
            // Create a Table Cell for the answers..
            out.println("<TD valign=\"TOP\" width=\"25%\"><P>");
            out.println("<TABLE>");
            // Get an Enumeration of all the possible ansewrs..
            Enumeration enum = vAnswers.elements();
            // Go through all possible ansewrs..
            while (enum.hasMoreElements()) {
                  out.println("<TR><TD align=\"RIGHT\">" + enum.nextElement() + "</TD>");
                  // Output the result to the Client..
                  out.println("<TD>&nbsp;-&nbsp;" + roundUp(Math.abs(resultMap[answerIndex])) + "%</TD>");
                  // Do we have more answers to display?
                  if (enum.hasMoreElements()) {
                        // Increase the answer's Index..
                        answerIndex++;
                  }
                  out.println("</TR>");
            }
            out.println("</TABLE>");
            // We're done displaying the answers, close the Table Cell..
            out.println("<BR></P></TD>");
      }

      private void displayResultsForm() {
            // Ask the user to answer the questions..
            out.println("<P>The Results are:</P>");
            // Add the Questions and their Answers in an HTML Table..
            out.println("<TABLE border>");
            // Start from Question #1, which index is actually 0..
            int questionIndex = 0;
            // Start with the darker background
            boolean dark = true;
            // Get an Enumeration of the questions..
            Enumeration enum = vQuestions.elements();
            // Go through all the questions..
            while (enum.hasMoreElements()) {
                  // Start a new HTML-Row for the current Question..
                  out.print("<TR style=\"background:#");
                  // Add the row's colour..
                  out.print(dark ? "A0A0A0" : "C0C0C0");
                  // Close the TR tag..
                  out.println("\">");
                  // Display the next question..
                  displayQuestion(questionIndex, enum.nextElement().toString());
                  // Display all possible answers..
                  displayResults(questionIndex);
                  // Close the Question's Row..
                  out.println("</TR>");
                  // Do we have more Questions to display?
                  if (enum.hasMoreElements()) {
                        // Change the colour for the next Question's Row..
                        dark = !dark;
                        // Increase the Question's index..
                        questionIndex++;
                  }
            }
            // Close the TABLE tag..
            out.println("</TABLE>");
      }

      private void endResponse() {
            // Close the reply by sending the BODY and HTML closing tags..
            out.println("</BODY></HTML>");
      }

      // Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // First we process the Request to get all the parameters sent to us..
            processRequestInput(request);
            // Next, we prepare the Response object before we can reply..
            prepareResponse(response);
            // Did this user already take the Questionnaire?
            if (userName == null) {
                  // This is the User's first time filling the Questionnaire..
                  displayQuestionnaireForm();
            } else {
                  out.println("<H3>Dear " + userName + ", we thank you for filling our Course Questionnaire.</H3>");
                  // The User already filled the Questionnaire, so just display the results..
                  displayResultsForm();
            }
            // Finally, we end the Response and the reply is sent to the Client..
            endResponse();
      }

      // Process the HTTP Post request
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // First we process the Request to get all the parameters sent to us..
            processRequestInput(request);
            // Next, we prepare the Response object before we can reply..
            prepareResponse(response);
            // Now, we can process the Response itself, by sending our reply..
            processResponse();
            // Finally, we end the Response and the reply is sent to the Client..
            endResponse();
      }
}

//_____________________
// Question's file content
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
[answers]
Strongly Agree
Agree
OK
Disagree
Strongly Disagree
Not Applicable
[questions]
The purpose of the courses/lessons are made clear.
The structure of the lectures are well outlined.
The basic principles of the subject are made clear.
The course is interesting.
The exmaples given are helpful.
The lecturer is able to explain the material in a clear manner.
It is easy to take notes.
The lecturer arrives on time.

As you can see, QuestionnaireServlet demonstrates working with cookies, displaying different HTML elements and different forms based on user-input.
0
 

Author Comment

by:javabeginr
ID: 13898456
Thanks for the example.  
0
 
LVL 9

Expert Comment

by:doronb
ID: 13899400
You're welcome and I hope it will help you in your project.
0
 

Author Comment

by:javabeginr
ID: 13906472
Doronb,

Can you add the jsp so I can see how you call the things you're displaying on the jsp?
0
 
LVL 9

Expert Comment

by:doronb
ID: 13906886
The servlet does the work in my previous sample, so there is no JSP actually.

A good example of a JSP iterating through data could be found here: [ http://java.sun.com/products/jsp/tutorial/TagLibraries16.html#62513 ]
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question