O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required