aspose file tools*
The moose likes Servlets and the fly likes Not able to navigate the user to another jsp in servlets using RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not able to navigate the user to another jsp in servlets using RequestDispatcher" Watch "Not able to navigate the user to another jsp in servlets using RequestDispatcher" New topic
Author

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

Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
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

Joined: Jan 08, 2009
Posts: 1477
    
    6

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



Swastik
Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
ohkk ill make these changes..............n please tell me if any other changes are to be made..
thanks for the reply...
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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

Joined: Jan 10, 2002
Posts: 61221
    
  66

Please read: UseTheForumNotEmail


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
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

Joined: Jan 08, 2009
Posts: 1477
    
    6

Once the user authentication is done, to which page is it going?
Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
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

Joined: Jan 08, 2009
Posts: 1477
    
    6

But you said that you are not able to navigate the user to other page?
Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
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

Joined: Jan 08, 2009
Posts: 1477
    
    6



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

Joined: Mar 18, 2011
Posts: 12

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

Joined: Jan 08, 2009
Posts: 1477
    
    6

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: 213
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: 213
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
Thankyou all ..my problem is solved.. I removed the Ajax code and used simple jsp..
Its working great now...

Thanks all of you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to navigate the user to another jsp in servlets using RequestDispatcher