• Post Reply Bookmark Topic Watch Topic
  • New Topic

User validation  RSS feed

 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to write a JavaBean that includes a connection to a database and will compare the entered details of a user (i.e username and password) to that stored in the database. I have managed to accomplish this with JSP but require the login to establish over a session and therefore require a java bean. How can I include a query in the bean which will compare the supplied details with what is in the database? Any help would be appreciated.
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand correctly, you are needing to move the JDBC logic from the JSP page, to a JavaBean? This is good practice, as most if not all of your business logic (i.e. interaction with database), should be kept out of the JSP page. It should be rather simple, as long as you understand how to create and use a JavaBean in the web context. Simply make a Java class, called Authenticator for instance, keeping in mind the requirements of a JavaBean (i.e. a constructor with no parameters), and construct a method, authenticate(), which holds the logic to authenticate a user (the DB connection, SQL query, etc.).
So, in essence, all you need do from your JSP page is the following:

This assumes you have something like the following declared in your JSP:

So basically, your Authenticator class with have an authenticate method which accepts two parameters, a username and password, and then builds an SQL query based on these parameters. Hope this helps,
WS
[ March 01, 2004: Message edited by: Winston Smith ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!