Reputation: 2517
I have a website which would be having around 15 session variables per user. I recently came to read an article which says that "session variables are evil and they affect the performance of the application". I was really disappointed by reading that article as I couldn't find any other way through which I can access the variables on other page.
Consider the below scenario,
I have a forum website in which when a user clicks a particular question, ForumSingleQuesitonController
is called which stores the question, its answers, the comments of questions and answers both within the object of ArrayList<ForumSingleQuestionBean>
and this object is stored by me in the session.
Now I use resonse.sendRedirect("pages/forum_single_question.jsp");
to goto the forum_single_question.jsp
page, from which I access the session variable and prints out it's values.
Now my question is how can I perform this procedure i.e. passing a variable from Controller(Servlet)
to JSP
without using session variable.
Thanks in advance
Upvotes: 1
Views: 1502
Reputation: 94469
I would recommend performing a forward
from the servlet. This will pass all of the request parameters to the JSP.
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/forum_single_question.jsp");
dispatcher.forward(request,response);
If you need to include additional attributes set them prior to the forward using:
request.setAttribute("attributeName", value);
Upvotes: 2