QuestionQuestion

Form Data
In this project, you will probably copy and rename your servlet a lot, since later problems are similar to earlier problems. When you do this copying, always change the URL.
If you have two servlets with the same address, the server will totally ignore one.
1. Open the “forms” project. Run the ThreeParams servlet. You should see null for all three parameters. Run it again by starting with threeparams form.html and submitting the form. You should now see the entries from the textfields.
2. Make a new Eclipse project called exercises-forms (or some such). Use this project for the rest of the exercises. Copy the ThreeParams servlet from my “forms” project and put it in a new package/directory in your project. Similarly, make a copy of three-params-form.html. Test the servlet and the form.
3. Copy/rename the ThreeParams servlet and associated form and have the new versions use POST instead of GET. Note that you will have to make small changes to both the servlet and the form. You will probably need to restart Tomcat after making the changes (R-click Tomcat and choose Restart).
4. Use three-params-form.html to send data to the ThreeParams servlet that contains HTML-specific characters. Verify that this can cause malformed results. Make a variation of the servlet that filters the strings before displaying them. Be sure to copy ServletUtilities from the “forms” or “test-app” project first, so that you can simply do this: someString = ServletUtilities.filter(someString);
5. Make a “registration” form that collects a first name, last name, and email address. Send the data to a servlet that displays it. Feel free to modify the ThreeParams HTML form and servlet to accomplish this. Next, modify the servlet to use a default value (or give an error message) if the user omits any of the three required parameters.
6. [Hard; for the truly inspired.] Make a variation of the previous servlet and accompanying form, but, in this case, if the user fails to supply a value for any of the fields in the form, you should redisplay the form but with an error message saying that the value is missing. Don’t make the user reenter values that they’ve entered already. Hint: you have two main choices given the tools available to us so far: have one big servlet that generates both the HTML form and the results page (the form submits the data to itself), or two separate servlets (one that generates the HTML form and the other that generates the results page).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

@WebServlet("/registration")
public class Registration extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,
                   HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Registration";
   
    String error = "";
    if (request.getParameter("param1") == null ||
    request.getParameter("param1").trim().isEmpty()) {
    error += "<h3>First Name is missing</h3>";
    }
   
    if (request.getParameter("param2") == null ||
    request.getParameter("param2").trim().isEmpty()) {
    error += "<h3>Last Name is missing</h3>";
    }
   
    if (request.getParameter("param3") == null ||
    request.getParameter("param3").trim().isEmpty()) {
    error += "<h3>Email is missing</h3>";
    }
   
    if("".equals(error)) {
    String docType =
      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
      "Transitional//EN\">\n";
   
    out.println(docTyp...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$50.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Web Development (HTML, XML, PHP, JavaScript, Adobe, Flash, etc.) Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats