Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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 ]
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic