Lab 3-3 — Using EL
Instructions
- Create a servlet named Lab33Servlet and add it to the java112.project3 package.
- In the
doGet()
method of the servlet, create a local variable that has the type ofMap
. Instantiate a new HashMap object and assign it to the variable. -
Using the
put(<K>, <V>)
method add the following data to the map.- A number
- A sentence of plain text
- A fragment of HTML, like an
<h2>
tag text inside it - A
new Date()
object
Map map = new HashMap(); map.put("number", 1); map.put("text", "This is some sample text."); map.put("html", "<h2>This is an h2</h2>"); map.put("aDate", new Date());
-
Using the
setAttribute(<K>, <V>)
method of theHttpServletRequest
interface, add the map to therequest
parameter.request.setAttribute("myMap", map)
-
Forward to a JSP page named
lab33.jsp
.String url = "/lab33.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url); dispatcher.forward(request, response);
-
Create a JSP page named
lab33.jsp
and save it to your public_html directory. The page does not need use the same HTML as yourindex.jsp
page. Just make a very simple page. -
Add some HTML tags and EL statements to display the data in the map.
<h2>Map on a JSP Page</h2> <p>${myMap["number"]}</p> <p>${myMap["text"]}</p> ${myMap["html"]} <p>${myMap["aDate"]}</p>
-
Add a link to the
Lab33Servlet
to your website's menu.
Screenshots
To receive credit for this lab save a screenshot in the projects/screenshots/week9
directory.
lab3-servlet.png
: The servlet running in the browser (it should show the jsp and the data you added to the map).
Submit Weekly Labs
- Add, commit, and push!
- Verify all work, including screenshots are visible in GitHub.
- Create a new issue in GitHub: "Week 9 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?
-
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.
Additional Considerations
- Issue created correctly with thoughtful answers to the reflection questions.
- EL (Expression Language) is used correctly.