Our MVC app depends on attributes

Remember in the original MVC beer app, the Servlet controller talked to the model (Java class with business logic), then set an attribute in the request scope before forwarding to the JSP view.

The JSP had to get the attribute from the request scope, and use it to render a response to send back to the client. Here’s a quick, simplified look at how the attribute goes from controller to view (just imagine the servlet talks to the model):

Servlet (controller) code

image with no caption

JSP (view) code

<html><body>
Hello
<%= request.getAttribute("name") %>

</body></html>

Note

Use a scripting expression to get the attribute and print it to the response.

(Remember: scripting expressions are ALWAYS the argument to the out.print() method.)

image with no caption

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.