Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to send error messages from sendRedirect to Jsp from a servlet

 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a login page which is validated at the server side.When the login fails,the servlet which does the processing calls the sendRedirect to the login jsp.I want to display some error message when the jsp is called back again with some message like "Login failed,Try again!" at a particular place on the login jsp.

Is it possible to do this by sendRedirect?

Can some one please advice me on this?

Thanks in advance!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
 
Prashant Hurria
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using sendRedirect.Send redirect is normally used when you need to redirect the user to somewhere outside your application.Use RequestDispatcher instead and put any error messages in the request scope.
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Prashant,

I used request dispatcher and send the attribute inside the req object to the page where I want to display the message.

It works for me now!!

Thanks for your advice!!
 
Prashant Hurria
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are most welcomed.
Good that this worked for you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prashant Hurria wrote:Why are you using sendRedirect.Send redirect is normally used when you need to redirect the user to somewhere outside your application.

Not generally true.

Redirects are use liberally within the same web application when its appropriate to generate a new response.
 
Prashant Hurria
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Not generally true.

Redirects are use liberally within the same web application when its appropriate to generate a new response.


Bear Bibeault i didnt have the chance or need to use sendRedirect while redirecting within my application (That is what this forum is about - learning from each other ).It would be great to learn from you that in what situation you would want to have a new response ?? please elaborate. Thanks in advance.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prashant Hurria wrote:It would be great to learn from you that in what situation you would want to have a new response ?? please elaborate.


Redirect is used in PRG-pattern
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic