Reputation: 2730
I need to pass hidden parameters using response.sendRedirect (I don't want to use forwards in some cases).
Because I don't want to use GET parameters like ?par1=val1&par2=val2&,... I'm using session objects like this:
session.setAttribute("error_message", "Error: e-mail is null");
response.sendRedirect(targetURL);
And when the "targetURL" is loaded (it would be a JSP file), I read the value and then I remove that session attribute:
if(session.getAttribute("error_message") != null) {%>
<h4><%=session.getAttribute("error_message").toString()%></h4> <%
session.removeAttribute("error_message");
}
%>
Do you think it's a reasonable/reliable kind of do what I need? Is it bad for performance? What do you think about it? Keep on it or thrash that code?
Thank you!
Upvotes: 0
Views: 357
Reputation: 676
It's okay to use session in your case. What you need to keep in mind is that session isn't thread-safe, once if another tab in the same browser window remove the attribute, the user will gett an error.
It's not bad for performance.
If you don't want to pass data by URL and you're using response.sendRedirect()
then session scope is a good option for you.
Upvotes: 1