• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Difference between servlet and jsp

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the difference between servlet and jsp..

if its possible please give more information..
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know some of the following:

1] Servlet is mainly used for business logic, and JSP is mainly used for presentation.

2] In Servlet, you put HTML inside Java and in JSP you put Java inside HTML.

Some additional informations:

JSP ultimately converted into servlet before execution.
[ September 27, 2005: Message edited by: rathi ji ]
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A servlet is a special class that is instantiated by the web container to handle HTTP requests. Typically it delegates to JavaBeans or EJBs to perform business logic before transferring control to a JSP.

A JSP is a web page that includes some dynamic content (e.g. JSP scriptlets, JSP expressions, JSP tags) and is used to present a view to the user. At execution time it actually runs as a servlet (it is compiled into a servlet).

For more details you may be interested in exploring lessons 1 and 6 at: http://java.sun.com/developer/onlineTraining/J2EE/Intro2/j2ee.html
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is not good practice to put the business logic in the servlet. We shouldn't assume that our application will be only accessed by the web. It is always better to place the business logic in the Model(Plain Old Java Code). Servlet can be used as a controller between the Java coding(Model) and JSP (or) Html (View - Presentation)

Whether my statement is correct??
 
Keith Pitty
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the Model View Controller (MVC) pattern is a widely accepted good practice for separating concerns in a J2EE web application. JavaBeans or POJOs (or EJBs) are used for the Model, JSPs for the View and Servlets for the Controller.
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Mark. Use POJO's and EJB's for business logic. Your application can be accessed by mobile phones, PDA's, browser, fat clients etc.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A servlet looks like Java with some statements that write HTML (maybe).

An JSP looks like HTML with some Java script (maybe).

So a servlet is better suited to Java-like stuff: logic, complex processing, nifty OO models. A JSP is better suited to presentation stuff: HTML, JavaScript, etc.

A common model is for incoming GET and POST requests to hit a servlet which calls other Java classes that handle any inbound data and generate any outbound data. When all the Java work is done, the servlet forwards to a JSP that prepares the response page.

Under the covers the container compiles a JSP into a really ugly servlet, so the two can do most of the same things. But it's good to have a clear idea of what their roles are and how you want them to be different. Consider coding rules like no HTML in servlets and no Java in JSPs.

For more details, google and read up on MVC-2, front controller or Struts architecture.

-edit-

Wow, a bunch of people said similar things while I was away reading my mail!
[ September 27, 2005: Message edited by: Stan James ]
 
What's brown and sticky? ... a stick. Or a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic