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 -
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..
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.....
Joined: Apr 04, 2006
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 !
Joined: Mar 18, 2011
Thankyou all ..my problem is solved.. I removed the Ajax code and used simple jsp..
Its working great now...