JavaBeans, Tomcat and deployment.

M

Mike Cox

I recently built a simple Tomcat servlet that accessed a database. Reading
through various documentation I discovered JavaBeans. I don't understand
what they are, as I'm already doing database access through the servlet and
a jdbc connection.

Why are there JavaBeans if one can do database access through Servlets? Can
one even do JavaBeans with just Jakarta/Tomcat 4.1? If so, is there a
simple example that shows JavaBeans, Servlets and JSP in action so I could
better understand the relationships between them?

Finally, I have a question about Tomcat itself. If one wanted to deploy an
application how would the users get to it? The default config is to
localhost and to listen on port 8080. How would someone visiting the site
even be able to reach the servlet when it is on port 8080? Or is that
something that everyone changes to port 80 when they are ready to deploy?

In advance I would like to thank you for your help.
 
M

Mike Cox

xterm wrote:

Thank you for your response.
You can use JavaBeans with Servlets yes. Basically a Java Bean (not an
EJB) is a reusable component that follows a certain template for use in
your servlets/jsp.

What is the difference between a Java Bean and an EJB?
A good example of a javabean would be a Shopping
cart bean which can hold the orders of a User throughout the Session.
Another example is using a javabean to store information about a user
for authentication purposes.

Can Tomcat do JavaBeans?
Tomcat is a servlet container, users/companies do not use it as a
webserver, however it is possible to do so for development. You can use
Apache HTTPD and Tomcat together if you wish to use a stable system.

I see. Is this better than using PHP or ASP?
 
X

xterm

You can use JavaBeans with Servlets yes. Basically a Java Bean (not an
EJB) is a reusable component that follows a certain template for use in
your servlets/jsp. A good example of a javabean would be a Shopping
cart bean which can hold the orders of a User throughout the Session.
Another example is using a javabean to store information about a user
for authentication purposes.

Tomcat is a servlet container, users/companies do not use it as a
webserver, however it is possible to do so for development. You can use
Apache HTTPD and Tomcat together if you wish to use a stable system.
 
X

xterm

What is the difference between a Java Bean and an EJB?

Nothing alike. There are 2 types of Java Beans, both imply a reusable
component, however 1 type can refer to a custom created Graphical
Component that can be integrated with Graphical applications, the other
type is a reusable component that can be integrated with web
components, example:
class User{
private String username;
private String password;
public String getUsername(){
return username;
}
public String getPassword(){
return password;
}
// and the setters here
}

in this case you can use your java bean withing your web components
using jsp taglibs such as:
<jsp:useBean id="usr" class="User" scope="session">
and you can invoke the jsp:setProperty and jsp:getProperty to fetch/set
data throught the session scope.

an EJB is a whole different concept, it's a component that can be
deployed on Application servers, they can provide several features,
they can be looked up using naming services and they make use of the
Application Server's stability, security and the lot... read about J2EE
if you wish to learn more.
Can Tomcat do JavaBeans?
Tomcat is a servlet/jsp container, hence yes it does contain the
architecture.
I see. Is this better than using PHP or ASP?
I cannot answer this since it'll cause a flame war, but to parse PHP
scripts you need the interpreter which can be integrated with apache's
httpd or microsoft's IIS, and for ASP the only way to parse asp pages
is using IIS. With tomcat you most probably can hook it up to any
webserver that supports connectors to tomcat. Basically requests are
handled by the webserver and dispatched to the servlet container
depending on the request, whether it's a jsp, servlet or any dynamic
content. This is usually the way to go, if you need security and faster
loading (eg: hosting all static content on the webserver, and keep the
dynamic content on the servlet container).

Distributed Systems is a very interesting field, you should read about
it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top