• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

User validation

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic