1. In a previous problem, you had two pages. You used the Referer header to force users to get to page 2 by following a link from page 1. Now, suppose that it is not necessary to always go to page 1 before page 2; you just want to make sure that users have been to page 1 at least once before they are allowed to visit page 2. For example, page 1 might be a page that introduces the site and gives some legal disclaimers, and users are required to visit that page at least once before they can see the second page.
Make a small page that displays some simple information of your choosing. Make another page that lets users choose the foreground and background color that they want the first page to use. For example, if users never visit the the color choice page, the main informational page should use default colors of your choosing. But if a user visits the color choice page and chooses a yellow background and red foreground, all subsequent visits to the main page by that user should result in red on yellow. There is no need to vet the colors; you can accept whatever color values the user gives you.

1. Use session tracking to make a servlet that says "Welcome Aboard" to first-time vis-
itors (within a browsing session) and "Welcome Back" to repeat visitors. If you did
this same task earlier with the Cookie API, was this servlet harder or easier than the
equivalent version using cookies explicitly?
2. Write a servlet that displays the values of the firstName, lastName, and emailAddress request parameters. But, remember what users told you in the past, and use the old values if the current values are missing. So, if a parameter is missing and the client is a first-time visitor, have the servlet list "Unknown" for the missing values. If
a parameter is missing and the client is a repeat visitor, have the servlet use previously- entered values for the missing values. This should definitely be easier than a version that uses cookies explicitly.
3. Make a servlet that prints a list of the URLs of the pages that the current user has used to link to it (within the current browsing session). That is, if one user has followed hypertext links from three different pages to the servlet, the servlet should show the user the URLs of those three pages. Test out your servlet by making a couple of different static Web pages that link to it. If you feel inspired, modify the basic approach from the notes so that you do not store repeated entries; if the same user follows a link from pagel to the servlet twice, the servlet should list the URL of page 1 only once in the list. Start with my ShowItems class, and make a few small changes such as getting the data from a request header (which one?) and changing doPost to doGet. If you are unfamiliar with the list-related data structures in Java, see the notes on the next page regarding the ArrayList class.

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.

public class page1 extends HttpServlet {

    * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
    * methods.
    * @param request servlet request
    * @param response servlet response
    * @throws ServletException if a servlet-specific error occurs
    * @throws IOException if an I/O error occurs
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

       // get session
       HttpSession session = request.getSession();
       // check asscesion to page2
       Integer accessCount = (Integer) session.getAttribute("accessCount");
       // default value
       String background_color = "white";
       String color = "black";
       // ther user had accessed page 2 before
       if (accessCount != null) {
            // if he set up colors then we take them here
            if (session.getAttribute("background_color") != null) {
                background_color = (String) session.getAttribute("background_color");
            if (session.getAttribute("foreground_color") != null) {
                color = (String) session.getAttribute("foreground_color");

       try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<title>Servlet page1</title>");

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

for this solution

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.

Upload a file
Continue without uploading

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