This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
Not able to navigate the user to another jsp in servlets using RequestDispatcher
Tanima Gupta
Greenhorn
Joined: Mar 18, 2011
Posts: 12
posted
0
Hello,
I really need your help in this....I am making a jsp with ajax login page... using eclipse helios, Tomcat as server and DB2 as my database server..
I made the jsp login, and have successfully passed the parameters over to servlet for verification from database..
As the username and password gets verified from the database, I wish the servlet to navigate the user to another jsp page.. for this i tried to use both response.sendRedirect() and RequestDispatcher.forward(request,response) .....In both cases, the code of the new jsp page is sent back to login.jsp as a response in xmlhttp.responseText (this was used in case the login failed, servlet can return a "false" for failed login authentication to be printed on login page
Here is the code -
VerifyLogin.java
And this a part of login.jsp which i used for response for failed login authentication -
Kindly guide me on how to navigate to another jsp page..
Thankyou..
Swastik Dey wrote:What exact exception message is it showing? I could not reply to your message there because you probably don't accept private messages.
thanks for the reply..
my other problem is solved..it was the problem of DB2
Right now i am not able to navigate the user to another page..any suggestions?
So, when the user name password matches, the value in variable flag must be true. Do you mean to say that even if it is getting a true value, the page is not getting redirected to success.jsp page?
Yogendra Joshi
Ranch Hand
Joined: Apr 04, 2006
Posts: 206
posted
0
Tanima Gupta wrote:
Swastik Dey wrote:But you said that you are not able to navigate the user to other page?
ohkk sry....i want it to go to success.jsp but it is going to my login page......as a response
Tanima, It would be great if we can minimize the use of slang words. You should use sorry for sry. We have people coming from a lot of different communities who would not understand what your "sry" means.
Keep it Standard English which everyone can understand and hence reply you better with correct answers.
Have Fun Learning !
Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Yogendra Joshi
Ranch Hand
Joined: Apr 04, 2006
Posts: 206
posted
0
I have some suggestions on your code.
1. You should not be doing the database code inside your servlet. Remember, Servlet is a Controller and hence not a place for writing business logic. I would suggest you to create a DAO class with a method like public boolean validateUser(String userId, String password) and call that method from your servlet.
If the validateUser method returns true, then you would forward the user to success.jsp.
2. Use boolean true instead of string, this would make sure that there are no white spaces and you would be saved of writing the equals and equalsIgnoreCase. I am saying this from Performance point of view. Something you can do with the boolean should not be replaced with a costly equals call. Equals call is heavy. So avoid it as far as you can.
Happy Coding and Keep posting your problems. We are all learning !
Tanima Gupta
Greenhorn
Joined: Mar 18, 2011
Posts: 12
posted
0
Thankyou all ..my problem is solved.. I removed the Ajax code and used simple jsp..
Its working great now...