Skip to content

Lab 3-3 — Using EL

Instructions

  1. Create a servlet named Lab33Servlet and add it to the java112.project3 package.
  2. In the doGet() method of the servlet, create a local variable that has the type of Map. Instantiate a new HashMap object and assign it to the variable.
  3. 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());
    
  4. Using the setAttribute(<K>, <V>) method of the HttpServletRequest interface, add the map to the request parameter.

    request.setAttribute("myMap", map)
    
  5. Forward to a JSP page named lab33.jsp.

    String url = "/lab33.jsp";
    
    RequestDispatcher  dispatcher = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
    
  6. 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 your index.jsp page. Just make a very simple page.

  7. 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>
    
  8. 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.

  1. 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

  1. Add, commit, and push!
  2. Verify all work, including screenshots are visible in GitHub.
  3. Create a new issue in GitHub: "Week 9 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?
    
  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.

Additional Considerations

  • Issue created correctly with thoughtful answers to the reflection questions.
  • EL (Expression Language) is used correctly.