Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variable from a servlet to a jsp page?

Tags:

java

jsp

servlets

I have a servlet (front-controller), which analyse the request, prepare some necessary data (model) and then should pass it to the jsp to be rendered.

How should I pass the data from servlet to jsp? (I hoped that it was possible to add new parameters to parameters map in the request object, but that map is unmodifiable).

I can add attributes to the request but I don't know how to retrieve them from the jsp.

All the data should be in the request scope. What's the correct way?

like image 943
Roman Avatar asked Feb 08 '11 15:02

Roman


1 Answers

I can add attributes to the request but I don't know how to retrieve them from the jsp.
You don't need to specifically 'retrieve' them, just referring them works

request.setAttribute("titleAttribute", "kittens are fuzzy");

and then

Title here: ${titleAttribute}
like image 124
Nikita Rybak Avatar answered Sep 24 '22 21:09

Nikita Rybak