wood burning stoves 2.0*
The moose likes Servlets and the fly likes Difference- servlet and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference- servlet and jsp" Watch "Difference- servlet and jsp" New topic
Author

Difference- servlet and jsp

Rahul Ghai
Greenhorn

Joined: Nov 03, 2000
Posts: 21
Hi,
What are the differences between servlet and jsp?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
A servlet is a piece of program that sits on your webserver, handles incoming requests and often returns a dynamically built HTML( or browser-renderable ) content.
A JSP( Java Server Pages ) on the otherhand, is an advanced HTML content that can contain inline-java code and calls to Servlets.
A Servlet is a content generator while JSP is the content itself which can include within, calls to different content generators.
Hope that helps,
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It is important to remember, though, that a JSP file is really just an alternative way of specifying a servlet. A JSP is always converted to a servlet and compiled before it can be run to generate a page.
JSP is easier to use if your page has a lot of static content (HTML which is the same for every request) and only a small number of relatively simple calls to generate dynamic content. Traditional servlets are a better choice if you need more sophisticated processing or only have a small amount of static HTML in the page.
Don't forget that there are also other ways of mixing static and synamic content on the same page. Several of my projects use WebMacro or another templating engine of my own design, or generate XML which is formatted using XSL stylesheets.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Edgar Sanchez
Greenhorn

Joined: Oct 12, 2000
Posts: 21
A servlet is a Java class that can be invoked from a browser (thru the good services of a servlet-enabled web server). This class receives an object representing the calling web element and an object representing the answer to be sent to the browser, typically this answer is an HTML page (painfully) created thru a series of println calls. A servlet is thus not well suited to create complex pages.
A JSP page on the other hand is an HTML page with Java code embeded, which is handy if you have lots of static HTML (tables, gifs, etc.) The embedded Java code is expected to instantiate some Java objects and put dynamic values inside <TD>, <INPUT> and other HTML tags. As Frank remarked a JSP page is actually converted in a servlet before it's run so its efficiency is generally acceptable.
Hope this helps (and my apologies for any misleading info)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference- servlet and jsp