• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble with attributes and redirect

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Login.jsp in which I have a form for the user to submit his username and password.
This form is sent to a servlet that processes the login information. If correct, it goes to welcome.jsp. If incorrect, it comes back to Login.jsp giving the user an error message and allowing him to re-enter his username and password.
In my servlet, I use-
request.setAttribute("incorrectLogin", "Incorrect Login.");
res.sendRedirect("login.jsp");
In my JSP, the Java code is-
<%
if( ((String)(request.getAttribute("incorrectLogin"))) != null )
{
String inCorMess = "Incorrect username or password. Please try again.";
out.println("p align=center>" + inCorMess + "<p>");
}
%>
I do return to login.jsp but no message is displayed. How do I correct this?
Have spent too much time and have found no answer.
[ April 20, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you redirect, a new request is generated by the browser and attributes that you have placed on the old request are not available.
You should explore using a forward rather than a redirect.
P.S. I also edited your subject to be more descriptive -- please be sure to make your subject lines more decriptive in future posts.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!