aspose file tools*
The moose likes JSP and the fly likes Login JSP if condition and redirecting issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Login JSP if condition and redirecting issue" Watch "Login JSP if condition and redirecting issue" New topic
Author

Login JSP if condition and redirecting issue

Tuhin Bagh
Greenhorn

Joined: Mar 23, 2012
Posts: 7

Heyya fellas!
I'm trying to do a basic (no strict rules set yet ) jsp login authentication page, I applied my logic and wrote a code, i think i problem is in "IF Condition" and i'm not sure which is the redirection method.
The setup is like this, there is a .accdb name Userlog, from which the program accesses the username and password, if true then redirects to Admin.html!
Here the code

---------------------Html code--------------------------------------


---------------------Jsp code--------------------------------------------


Helpppp pleaseeee...!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

Step 1: Change your form to submit its values to a servlet, not a JSP.
Step 2: Replace the JSP that's the target of the form action with a servlet. JSPs should never be used for processing, just for creating views. And Java code should never appear in a modern JSP.

Once you've done that we can take it from there.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tuhin Bagh
Greenhorn

Joined: Mar 23, 2012
Posts: 7

Bear Bibeault wrote:Step 1: Change your form to submit its values to a servlet, not a JSP.
Step 2: Replace the JSP that's the target of the form action with a servlet. JSPs should never be used for processing, just for creating views. And Java code should never appear in a modern JSP.

Once you've done that we can take it from there.

Sir i knew that java shouldn't be used ..!! but my college project should be totally in jsp n html :(
thought the above code was my logic, but if i use servelet , my marks will get deducted
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

Gotta love a course that ingrains bad habits.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You should use a PreparedStatement and put the username in the where clause*. That will return only zero or one results. If it's zero, login has failed. If it's one, you check the password.

It seems as if you store your passwords in plain text in the database. You really shouldn't, it's quite insecure. Everybody who can read your database can read all passwords. You should instead hash the passwords when storing them in the database, then hash the provided password and compare the hashes.

* The PreparedStatement can help you prevent SQL injection.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tuhin Bagh
Greenhorn

Joined: Mar 23, 2012
Posts: 7

:@ damm yeah Bear i agree..!!!
Rob :| i had seen those 1 and 0 condition codes, in many examples! can you please gimme the code! i'll be really thankful..!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You know how to add a where clause to your query, right? After that, all you need to do is change your while into an [t]if[/tt]. If it returns true, there is one result. Otherwise there are no results, and the user account simply does not exist.
 
wood burning stoves
 
subject: Login JSP if condition and redirecting issue