-
When do we use Servlets vs JSP/JavaBean
Hi,
I am a newbie in the Java development. I read about developing web applications
using Servlets as well as JSP/JavaBeans. Which approach is more flexible
in developing web application? What are the advantages of one over the other?
I would appreciate your comments on this or let me know where I can get more
information about comparison of these two techniques.
thanks
Hari
-
Re: When do we use Servlets vs JSP/JavaBean
"Hari" <haris1@avaya.com> wrote:
>
>Hi,
>
>I am a newbie in the Java development. I read about developing web applications
>using Servlets as well as JSP/JavaBeans. Which approach is more flexible
>in developing web application? What are the advantages of one over the other?
>
>
>I would appreciate your comments on this or let me know where I can get
more
>information about comparison of these two techniques.
>
>thanks
>Hari
I am also relatively new to EJB and related technologies, but I will give
you my opinions. Using Servlets to process client requests (http get, put,
or post), and returning the response to a jsp to generate the dynamic content
is a pretty simple technique, however I have found with some web servers
servlets are not as easy to work with as jsp's (configuring), so the method
I use is similar to the method described in the J2EE blueprints (which can
be downloaded from java.sun.com/j2ee). I actually use a simplified version
in which a jsp works directly with a JavaBean using the useBean tag. I like
the way jsp's work with JavaBeans, they allow you to access properties directly
using the getProperty and setProperty tags. When accessing the properties,
the jsp container converts the types for you (Strings on the jsp side, and
native java types on the bean side), this makes it pretty smooth. I use
the above mentioned JavaBean to talk directly to the controller (a session
bean), which in turn talks to the model (entity beans).
I don't know if this is any help.
KJ
-
Re: When do we use Servlets vs JSP/JavaBean
hi,
Adding to what KJ says (which I completely agree with) ...
In most web development environments, the HTML/Graphic designer and the application
developer work in co-ordination. The former make the HTMLs templates and
the latter add the application support to the templates. In this scenario,
working with JSPs are a lot easier than working with servlets. You are basically
restricting the out.println() usage to dynamic content only. So both can
work on the same page copy.
There are a few other considerations:
Java Server Pages ultimately are compiled into servlets by the application
server. So in effect you are maintaining 2 copies of the same file ... one
is the source JSP and the other is the compiled servlet. This doubles the
disk space usage.
Servlets lend themselves better for business logic than presentation. JSPs
are better for presentation. So your presentation logic should ideally exist
in JSPs while Servlets and EJBs handle the business logic.
Vikram
-
Re: When do we use Servlets vs JSP/JavaBean
Mixing presentation logic with the business logic (lets name it this way)
has never been a great idea. Checking if the user is authorized to see this
or that HTML block should not be mixed with the code that actually executes
a stored procedure in a remote Oracle8i database server and returns an output
parameter which value is compared to something bound to the HTTP session
to check if the user is authorized or not.
This weird example is a usual mistake.
Hope that helps,
Fernando Ribeiro
fribeiro
"Vikram Rajan" <vikramr@planetasia.com> wrote:
>
>hi,
>
>Adding to what KJ says (which I completely agree with) ...
>
>In most web development environments, the HTML/Graphic designer and the
application
>developer work in co-ordination. The former make the HTMLs templates and
>the latter add the application support to the templates. In this scenario,
>working with JSPs are a lot easier than working with servlets. You are basically
>restricting the out.println() usage to dynamic content only. So both can
>work on the same page copy.
>
>There are a few other considerations:
>Java Server Pages ultimately are compiled into servlets by the application
>server. So in effect you are maintaining 2 copies of the same file ... one
>is the source JSP and the other is the compiled servlet. This doubles the
>disk space usage.
>
>Servlets lend themselves better for business logic than presentation. JSPs
>are better for presentation. So your presentation logic should ideally exist
>in JSPs while Servlets and EJBs handle the business logic.
>
>
>Vikram
-
Re: When do we use Servlets vs JSP/JavaBean
It is hard to say what is a best to use. Ideally speaking in enterprise wide
system I would use all the three. EJB, Servlets and JPS together can be used
effectively to respresent the MVC architecture. The servlet should ideally
be used as a controller that triggers off a change in view or in the model
based on a user action. EJB forms the model and JSP forms the view.
-Harpreet
"Fernando Ribeiro" <fribeiro@bol.com.br> wrote:
>
>Mixing presentation logic with the business logic (lets name it this way)
>has never been a great idea. Checking if the user is authorized to see this
>or that HTML block should not be mixed with the code that actually executes
>a stored procedure in a remote Oracle8i database server and returns an output
>parameter which value is compared to something bound to the HTTP session
>to check if the user is authorized or not.
>
>This weird example is a usual mistake.
>
>Hope that helps,
>
>Fernando Ribeiro
>fribeiro
>
>"Vikram Rajan" <vikramr@planetasia.com> wrote:
>>
>>hi,
>>
>>Adding to what KJ says (which I completely agree with) ...
>>
>>In most web development environments, the HTML/Graphic designer and the
>application
>>developer work in co-ordination. The former make the HTMLs templates and
>>the latter add the application support to the templates. In this scenario,
>>working with JSPs are a lot easier than working with servlets. You are
basically
>>restricting the out.println() usage to dynamic content only. So both can
>>work on the same page copy.
>>
>>There are a few other considerations:
>>Java Server Pages ultimately are compiled into servlets by the application
>>server. So in effect you are maintaining 2 copies of the same file ...
one
>>is the source JSP and the other is the compiled servlet. This doubles the
>>disk space usage.
>>
>>Servlets lend themselves better for business logic than presentation. JSPs
>>are better for presentation. So your presentation logic should ideally
exist
>>in JSPs while Servlets and EJBs handle the business logic.
>>
>>
>>Vikram
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks