This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB, JSPs and JDBCs

 
Charlie Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
btw my message bean is shown below:

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
can I use useBean here??
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
ohh I see.

Thank you very much!

Good day!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic