Lab 4-4: Sessions
Instructions
-
Create a JSP page named project4Session.jsp. Use the template system we’re using for the project.
-
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}
-
Create a servlet named Project4SessionLab in the java112.project4 package.
- 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.
- Get the
- Forward to the project4Session.jsp page.
- Add a link to the servlet, not the JSP, to your menu JSP fragment.
- Build and deploy your web application.
- Access the lab servlet and make sure that the
project4SessionCounter
is incrementing. - 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
.
lab4-session.png
: The servlet running in the browser.
Submit Weekly Labs
- Add, commit, and push!
- Verify all work, including screenshots are visible in GitHub.
- Create a new issue in GitHub: "Week 14 ready for review".
-
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?
-
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.