This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

EJB, JSPs and JDBCs

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm new to EJBs and I've trying to create a web application which basically i'm just starting from the login page

I have created a message bean, entity bean and session bean for my user.

Then i created a jsp page which accepts the user's login username and password

I don't know how to check these details which those in the jdbc database :S

any help how i can connect to this jdbc database?

thnx a lot!

 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
btw my message bean is shown below:

 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused. If I understand the question correctly, the problem is how to use JDBC to check login data in a database - correct? If so, what does all the talk about various EJBs have to do with it?

Are you familiar with JDBC? Do you have the driver for whatever DB you're using?
 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In simple terms what I'm trying to do is this:
http://www.netbeans.org/kb/60/javaee/ejb30.html

but with JSPs...

I tried it with servlets and it worked but i couldnt get it to work with jsps :s
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charlie,

Can you kindly post the code for the JSP and/or the Servlet?

Thanks,
Reza
 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my REGISTER JSP:
Where the new user is supposed to enter details about him/herself



then this processes the register:

 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by the way, im making use of the javadb derby database - the jdbc/sample
 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so in other words I'm asking how to persist my new member to the jdbc/sample table called Members from a JSP.

The entity i am using for the members is called Members

Thnx
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a few options:

1. Use JNDI lookups inside the JSP to get a reference to the session bean to insert the record.
2. Use a Servlet handler/controller to inject the session bean via @EJB.
3. Use a JSF backing bean to inject the session bean via @EJB.

I would recommend option 3 if this is a real-life application, quite possibly with Seam. Option 1 would be acceptable for beginner code to learn the internals of the technology but really should be avoided in real life. If you are very averse to using JSF, I would suggest option 2. Another alternative is to use something like Struts 2. You may inject EJBs into Struts Actions with minimal effort. No technology will allow you to inject EJBs into JSPs. As of Java EE 6, JSP is mostly regarded as a legacy technology in favor of JSF/Facelets.

Look to the documentation of your application server on how to perform a JNDI look-up of a session bean if you opt to use JSP only.

Hope it helps,
Reza
 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnx very much!

I'll give them a go tonight hopefully I'll see something working.
 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can I use useBean here??
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charlie,

The useBean tag is not designed to access EJB directly. However, while using Seam, you can use EJB 3 session beans as backing beans through bean binding. In a plain JSP world, the class in the useBean tag would have to do a JNDI look-up for the EJB.

Hope it helps,
Reza
 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohh I see.

Thank you very much!

Good day!
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built 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