| Author |
how to send error messages from sendRedirect to Jsp from a servlet
|
Moieen Khatri
Ranch Hand
Joined: Nov 27, 2007
Posts: 144
|
|
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
Joined: Jan 28, 2008
Posts: 5575
|
|
|
http://www.coderanch.com/t/451830/JSP/java/show-validation-error-messages-jsp
|
 |
Prashant Hurria
Ranch Hand
Joined: Mar 23, 2009
Posts: 40
|
|
|
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
Joined: Nov 27, 2007
Posts: 144
|
|
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
Joined: Mar 23, 2009
Posts: 40
|
|
You are most welcomed.
Good that this worked for you.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Prashant Hurria
Ranch Hand
Joined: Mar 23, 2009
Posts: 40
|
|
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
Joined: Mar 24, 2008
Posts: 3673
|
|
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
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
 |
|
|
subject: how to send error messages from sendRedirect to Jsp from a servlet
|
|
|