• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to navigate the user to another jsp in servlets using RequestDispatcher

 
Tanima Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all make some changes in your servlet

The way you are doing the user authentication will make it slow, try to use PreparedStatement



Second problem is the way you are comparing strings, what you are doing is a reference comparison, what you need to do is a value comparison

 
Tanima Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohkk ill make these changes..............n please tell me if any other changes are to be made..
thanks for the reply...
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exact exception message is it showing? I could not reply to your message there because you probably don't accept private messages.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read: UseTheForumNotEmail
 
Tanima Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the user authentication is done, to which page is it going?
 
Tanima Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Once the user authentication is done, to which page is it going?


To success.jsp ...i.e. a new jsp file
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you said that you are not able to navigate the user to other page?
 
Tanima Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Just before implementing the above logic, could you please check what value are you getting in the variable flag?
 
Tanima Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Just before implementing the above logic, could you please check what value are you getting in the variable flag?


i checked..it gives false as a response in login page when username and password dont match..
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou all ..my problem is solved.. I removed the Ajax code and used simple jsp..
Its working great now...

Thanks all of you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic