Skip to content

Lab 4-4: Sessions

Instructions

  1. Create a JSP page named project4Session.jsp. Use the template system we’re using for the project.

  2. This page should have a title and one EL statement that outputs a session counter. Something really simple like this that should go in the content fragment.

    Session Count: ${project4SessionCounter}
    
  3. Create a servlet named Project4SessionLab in the java112.project4 package.

  4. This servlet will do the following in the doGet() method.
    • Get the session object for the request.
    • Create a local Integer variable named sessionCounter.
    • Get an attribute from the session named project4SessionCounter. You will need to cast it to an Integer and assign it to the sessionCounter variable.
    • If the sessionCounter variable is null then create a new Integer instance with a value of 1 and assign it to the sessionCounter variable and set an attribute into the session named project4SessionCounter with sessionCounter as the value.
    • If the sessionCounter variable is not null, then increment the variable and set an attribute into the session named project4SessionCounter with sessionCounter as the value.
  5. Forward to the project4Session.jsp page.
  6. Add a link to the servlet, not the JSP, to your menu JSP fragment.
  7. Build and deploy your web application.
  8. Access the lab servlet and make sure that the project4SessionCounter is incrementing.
  9. Access the lab servlet from a different browser. Not a new window in the same browser, but a different browser like Chrome.

Screenshots

To receive credit for this lab save screenshot(s) in the projects/screenshots/week14 directory.

You may combine the below into one screenshot and name it lab4.png.

  1. lab4-session.png: The servlet running in the browser.

Submit Weekly Labs

  1. Add, commit, and push!
  2. Verify all work, including screenshots are visible in GitHub.
  3. Create a new issue in GitHub: "Week 14 ready for review".
  4. Copy the below text and paste it into the "Add a description" textarea. Answer the reflection questions in the space provided.

    @kkschumacher
    
    ### How are you doing? 
    **Are you encountering any issues preventing you from completing this week's assignments? What can I do to better support you this week?**
    
    #### What did you find particularly enlightening this week?
    
    
    #### What challenges (if any) did you encounter in your learning this week?
    
    
    #### What questions (if any) do you have about the material covered this week?
    
    
    #### The above instructions ask you to cast to an Integer when retrieving the session attribute. Why do you need to do this? 
    
  5. Click "Submit new issue"


Rubric

All of the following must be satisfied to achieve a "Met" status

  • Screenshot clearly shows the servlet running in the browser.
  • Code and screenshot are properly named and saved in the correct directory.
  • All lab steps have been accurately and appropriately implemented.
  • Code adheres to the course coding standards.
  • Commit messages are concise, atomic, and effectively describe the change(s) made.
  • JavaDoc documentation is properly implemented, providing clarity and understanding of the code's functionality and usage.
  • External sources (websites, classmates, AI tools, etc), if utilized, are referenced and documented within the code as comments.

Additional Considerations

  • Issue created correctly with thoughtful answers to the reflection questions.
  • Correct answer to the casting question in the issue.