Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

JSP vs. Servlets

Thread view: 
Sathyaish - 09 Feb 2007 11:23 GMT
What are the pros and cons of using servlets instead of JSPs? As I
understand from my sparse reading of the topic so far, they're both
means of programming against the HTTP application model (i.e, request,
session, response, HTTP Runtime etc.).
senior - 09 Feb 2007 16:39 GMT
> What are the pros and cons of using servlets instead of JSPs? As I
> understand from my sparse reading of the topic so far, they're both
> means of programming against the HTTP application model (i.e, request,
> session, response, HTTP Runtime etc.).

http://www.devx.com/tips/Tip/25217
Lew - 09 Feb 2007 19:34 GMT
"Sathyaish" <sathya...@gmail.com> wrote:
>> What are the pros and cons of using servlets instead of JSPs?

> http://www.devx.com/tips/Tip/25217

Broadly speaking, JSPs are for the layout, or "view" aspect of an application,
and servlets are for the context and navigation, or "controller" aspect of an
application.

As the referenced tip suggests, JSPs look like HTML and servlets look like
Java. It is more natural in a JSP to concentrate on artifacts like drop-down
lists, submit buttons, headlines and the like. It is more natural in a servlet
to concentrate on things like parsing a request for its parameters, forwarding
the parameters to business and data logic, managing resource services,
coordinating processes and forwarding the view to the next JSP.

Both aspects of an application are required. Ideally, they will almost fully
separate concerns. You should nearly never have scriptlet (Java code) in a JSP
source file, nor response.out writes in a servlet .java source file.

Check around for the "model-view-controller" (MVC) application model, what Sun
calls the "Model 2 Architecture". It applies to Swing apps and other domains
besides Web apps. It ties in with service architectures and portals, even.

- Lew
Daniel Pitts - 09 Feb 2007 19:35 GMT
> What are the pros and cons of using servlets instead of JSPs? As I
> understand from my sparse reading of the topic so far, they're both
> means of programming against the HTTP application model (i.e, request,
> session, response, HTTP Runtime etc.).

A JSP is a different way to create a Servlet.
The focus of JSPs are presentation.  JSPs are great for creating HTML
from a template.
Pure servlets are great for business logic.

A common approach is to have a Servlet that handles the business logic
(I.E. a Controller), loads data to be rendered (I.E. Model) and passes
that data to a JSP to be rendered (I.E. View)

There are plenty of libraries that help you do this.
Where I work we tend to use Spring Framework with Tiles.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.