Question
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 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 {
       response.setContentType("text/html;charset=UTF-8");

       // 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("<html>");
            out.println("<head>");
            out.println("<title>Servlet page1</title>");
            out.println("</head
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.zip
Purchase Solution
$42.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 640 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,804+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,680+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,428+ sessions)
2 hours avg response

Similar Homework Solutions