This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 60046
    
  65

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: 60046
    
  65

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

Joined: Oct 27, 2005
Posts: 19541
    
  16

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: 19541
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Login JSP if condition and redirecting issue
 
Similar Threads
problem in running a servlet
Page displaying in IE6 and older versions but not in Higher versions, chrome and firefox also.
How to Pass, Username and password and Login from the url
Question on jQuery ajax functionality & troubleshooting called bean in JSF page
HTML does not print properly - table width exceeding 100%?