Reputation: 13
I have this situation where I am required to show where if user does not enter right password, the program will place an appropriate message in a session & will Dispatch back to the login jsp page and display the message.
I checked this one as well, Redirect to the same page but with a message in it
But when I try implement the answer, the eclipse gives me a red line over the code.
Here is my code,
String message = "Wrong Password!";
HttpSession session = session.setAttribute("message", message);
The error shown is Type Mismatch: Cannot Convert to from void to HttpSession
Any ideas where I am wrong or how can I do this?
Upvotes: 0
Views: 5772
Reputation: 5396
HttpSession session = session.setAttribute("message", message);
Above line is wrong. you need to do just a...
session.setAttribute("message", message);
That's it. And on jsp page while getting session value.
out.println(session.getAttribute("message"));
or
<%=session.getAttribute("message")%>
Upvotes: 0
Reputation: 5506
session.setAttribute("message", message);
this return type is void, hence your pionting to HttpSessoin
Object, so it is giving showing complier error.
Use this
HttpSession session = request.getSession(true);
session.setAttribute("message", message);
Upvotes: 0
Reputation: 19294
session.setAttribute()
returns "void
" and not "HttpSession
".
You need to get the session
from the request
and then use setAttribute()
on the session
attribute.
Upvotes: 1