Setting a request attribute works... but only for the JSP to which you forwarded the request

With the beer app, it made sense to store the model info for the client’s request in the request object, because the next step was to forward the request to the JSP responsible for creating the view. Since that JSP needed the model data and the data was relevant to only that particular request, everything was fine.

But that doesn’t help us with the email address, because we might need to use it from all over the application! There is a way to have a servlet read the init parameters and then store them in a place other parts of the app could use, but then we’d have to know which servlet would always run first when the app is deployed, and any changes to the web app could break the whole thing. No, that won’t do either.

image with no caption
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.