Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP vs. Servlets

Reply
Thread Tools

JSP vs. Servlets

 
 
Sathyaish
Guest
Posts: n/a
 
      02-09-2007
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.).

 
Reply With Quote
 
 
 
 
senior
Guest
Posts: n/a
 
      02-09-2007
On Feb 9, 2:23 pm, "Sathyaish" <(E-Mail Removed)> wrote:
> 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


 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      02-09-2007
"Sathyaish" <(E-Mail Removed)> wrote:
>> What are the pros and cons of using servlets instead of JSPs?


senior wrote:
> 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
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      02-09-2007
On Feb 9, 3:23 am, "Sathyaish" <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
Java servlets: Hi All! I want to display xml file in browser using servlets datta.saru Software 0 05-15-2006 03:30 PM
Threading - ASP. Net vs JSP/Servlets Peter Beck ASP .Net 4 11-19-2003 03:28 PM
Java Software JSP/Servlets for Website Template implmentation Prateeksha Web Services Java 0 08-29-2003 07:53 AM
Catching exceptions in JSP when they occur in Servlets Mick Java 0 08-06-2003 01:12 PM



Advertisments