• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass messages from login servlet to jsp

 
Andre Solberg
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When login fails in the servlet, I want to pass an error message to the page. I thought it would be as simple as just adding an attribute to the request, and then redirect back to index.jsp. But since the browser makes a new request, the attribute is lost. If I use the forward method, I get the error message just as I want, but the problem is that my login jsp, along with some other pages, are included in index.jsp. When I forward, the index.jsp doesn't behave normally, so I have to figure out another way.

Any tips?

Thanks!
 
Mos Jeff
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use AJAX. Generate an HTTP object that is sent to the servlet, the servlet can then respond by returning a response xml object. ie.

your jsp could then parse the response xml
 
Andre Solberg
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for your reply.

I'm not familiar with this approach, and to me it seems like a lot of code and rewriting of my application for such a simple thing as "wrong username or password". Any other suggestions? If not, I'll have to look into it.

Thanks
 
Mos Jeff
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
send 401 error as response in servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mos Jeff wrote:You can use AJAX.

A bit overkill, no?

The original problem is that a redirect creates a new request. SO any scoped variables placed on the original request do not take part in the redirected request. You can use the session (be sure to clean up) to pass the data across requests.
 
Andre Solberg
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, if placing the attributes in session is an okay approach, then there's no problem. Just thought it was a bad idea to place stuff like this in session scope, but if you say so then I can do it with a clear conscience

Thanks!
 
chima alaebo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to remove the attribute from the session scope when your true with it so as not to cause problem latter!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I already said:
(be sure to clean up)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!