This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSP and the fly likes Conditional Redirecting using JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Conditional Redirecting using JSP" Watch "Conditional Redirecting using JSP" New topic
Author

Conditional Redirecting using JSP

Agnit Chatterjee
Greenhorn

Joined: Mar 04, 2011
Posts: 24
I have a query........Suppose like in normal sites like gmail and yahoo where they have username password entry............suppose a user enters the username and password.......then the server checks from the database whether the username password pair matches and if it does automatically redirects to another page and if it doen't match then redirects to another page.......Can we achieve this using JSP

I have structured a program where the user enters the username and password and the program checks from the database to see if the username and password pair matches and if so then returns true else returns false

But I can't manage to make the program redirect to another page when the username and password pair does match!

Please help.......
Agnit Chatterjee
Greenhorn

Joined: Mar 04, 2011
Posts: 24
I have been able to do it..........something like this:



where users is the name of the bean I have used!!!

Just wanted to know whether this is the right way to it or not??? Is there any other alternate way?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35241
    
    7
Just wanted to know whether this is the right way to it or not?

Not really, there are several problems with the code.

Firstly, -assuming that "users.getVal()" returns a string- note that string equality is checked via the String.equals method, not via the "==" operator; that will cause problems.

Secondly, you really shouldn't keep code that controls the application flow in a JSP. Actually, you should not keep any Java code in JSPs. That has been a bad practice for many years now. Put such code in a servlet.

Lastly, it looks as if you're trying to redirect the browser to some external URL. You should do that on the server via HttpServletResponse.sendRedirect(...).


Android appsImageJ pluginsJava web charts
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

And besides not putting code into a JSP -- as Ulf pointed out, an irresponsible practice -- you should never rely upon JavaScript, which can be easily disabled, for security.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Conditional Redirecting using JSP
 
Similar Threads
Login Authentication & sendRedirect
Need Advice in my Project Design
perfect match in database
Any Suggestion?
Struts and Vlidation