aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB, JSPs and JDBCs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB, JSPs and JDBCs" Watch "EJB, JSPs and JDBCs" New topic
Author

EJB, JSPs and JDBCs

Charlie Jones
Greenhorn

Joined: Apr 06, 2009
Posts: 14
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

Joined: Apr 06, 2009
Posts: 14
btw my message bean is shown below:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42274
    
  64
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?


Ping & DNS - my free Android networking tools app
Charlie Jones
Greenhorn

Joined: Apr 06, 2009
Posts: 14
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

Joined: Feb 01, 2005
Posts: 580
    
    5
Charlie,

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

Thanks,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Charlie Jones
Greenhorn

Joined: Apr 06, 2009
Posts: 14
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

Joined: Apr 06, 2009
Posts: 14
by the way, im making use of the javadb derby database - the jdbc/sample
Charlie Jones
Greenhorn

Joined: Apr 06, 2009
Posts: 14
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

Joined: Feb 01, 2005
Posts: 580
    
    5
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

Joined: Apr 06, 2009
Posts: 14
Thnx very much!

I'll give them a go tonight hopefully I'll see something working.
Charlie Jones
Greenhorn

Joined: Apr 06, 2009
Posts: 14
can I use useBean here??
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
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

Joined: Apr 06, 2009
Posts: 14
ohh I see.

Thank you very much!

Good day!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB, JSPs and JDBCs