Fog Creek Software
Discussion Board

JSP + EJB (+ Java Beans)


My company is building a java app that uses EJB on the server side. As the client, we have a Swing java app.

We are looking to build some web-based interfaces for remote access that e.g. customers and suppliers of our client can use to access the system.

We (the developers) have a pretty good understanding and knowledge of writting EJB code and Swing clients, but we are not that familiar with JSP, at least not the kind of advanced JSP that connects to server side EJB's.

Do any of you know some online resources for this kind of thing? I have honestly not been able to find any thing through Google, only "Hello World" JSP tutorials.

I need something more advanced, espeacially about how design the web app so that as much java code is reused as possible and of course to optimize speed.

Any thing would be appriciated.


Rasmus Grunnet

Rasmus Grunnet
Sunday, December 15, 2002

I dont know if I understood your question..

JSPs are excuted serverside. Running a bean is simply a matter of including it and calling the methods.

Eric DeBois
Sunday, December 15, 2002

What I need is some guides on how to do this.

Rasmus Grunnet
Sunday, December 15, 2002

Here is an example of a common use:

<%@ page import="java.sql.*" %>

<jsp:useBean id="dbP" scope="application" class="dbp.dbPool"/>

Connection MyConnection = dbP.getCon();

The first line shouldnt be mysterious. The second creates an instance of the bean "dbp.dbPool" which happends to be a database connection pool.
Scope is set to application which means that the bean will not be destroyed after the page is done, but be kept alive untill the application shuts down. When the page (or any other page) tries to create the same objekt with the same name, they get the old one instead.

The third line uses the pool-objects getCon method to aquire a connection from the pool.

I dont know of any good online resources, but Wrox and Oreilly has some pretty good books on JSP. Perhaps there is free stuff on their sites?

Eric DeBois
Sunday, December 15, 2002

Here are some references:

Eric DeBois
Sunday, December 15, 2002

Use this and have a prototype in hours:

Philippe Back
Sunday, December 15, 2002

Have a look at the OpenSymphony tools. I don't do a lot of JSP work, but people I work with who have particularly recommend WebWork.

Daryl Oidy
Sunday, December 15, 2002

The Isavvix community not only provides a series of tutorials, but they also provide a 'dev space' so you can try the code on their servers.

Ged Byrne
Sunday, December 15, 2002

Jakarta Struts is pretty much the defacto standard for doing complicated JSP work.

Check out their website at:

and OnJava has a few tutorials too:

Miles Barr
Sunday, December 15, 2002

Thanks a lot for all the replies.

Rasmus Grunnet

Rasmus Grunnet
Sunday, December 15, 2002

<JSPs are excuted serverside. Running a bean is simply a matter of including it and calling the methods>

There is a difference between beans and ejbs, one is a tag that eventally creates an object in one of the servlet engine's container's collection depending on the beans scope (page,request,session,application) the other is an object that resides in the ejb container and has nothing to do in the servlet engine (it could even be on a seperate machine)

There is very little in a bean that is magical. it is simply an object (it does not have to subclass, or implement anything) with a constructor taking no args (For your purpuses, it gets instantiated the minute you declare it in a tag (although in reality the app server may cache these suckers ). Then to reference a bean you can call session.getAttribute, or application.getAttribute or request.getAttribute, and wah-la you can call its methods

In practice using beans is unneccessarily restrective, simply take the classes that connect to the EJB, put them in the appropriate collection ie ... session.setAttribute(key,object)
and pull them out same way as in the previous paragraph.
this has the advantage also, that you can use constructors with arguements.  Another advantage of this is you can then refer to the classes in scriptlets <% %> and don't have to use special tags.

If you have more questions email me at

Daniel Shchyokin
Monday, December 16, 2002

have a look at Barracuda.

Tuesday, December 17, 2002

*  Recent Topics

*  Fog Creek Home