aspose file tools*
The moose likes Servlets and the fly likes Diffrence between JSP and Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Diffrence between JSP and Servlets" Watch "Diffrence between JSP and Servlets" New topic
Author

Diffrence between JSP and Servlets

Amit Phagwani
Greenhorn

Joined: Jan 10, 2003
Posts: 6
hi ,
could any 1 pls tellme the diffrence between JSP and Servlets. When do you preffer one over the other.
thanx,
-a
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Amit
Technically there isn't much difference between JSP and Servlets. The JSP engine essentially parses the JSP file to create a Java program (servlet), and compiles and runs it just like it would any other servlet.
JSP pages are conventially used for presentation layer stuff, Servlets for the heavier business rules and logic stuff at the back, and a web application will typically consist of a combination of both.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Amit,
i have observed certain things.
1. if we use servlet then we can keep only the class files and hide the code- .java files (by jarring/tarring the code and put it away in file system) while we can't do it with JSP (we have to keep JSP files in the location).
2. webserver doesn't allow Indexing display on servlet directory so when we type /myserver/servlet/ only it doesnt show the servlets there in the servlet directory where as if we have not disabled the index listing on jsp directory then it will display list of all jsps when we type /myserver/jsp/ so essentially other parties get to know what is in the JSP dir
3. we have more control via servlets as JSPs will depend upon JSP Parsers etc. the reason for this is- sometimes we can't predict the behavior of JSPs we have across webserver instances (e.g. in the development and production environments) and it might happen that the same JSP that is working on one server will not work properly on other server even if we have followed standardized jsp code...(i've such bad experiences and going thru hard times right now ). In servlets , once we have the class file it would mostly work (except we encounter some class loading sequence or other wiered issues) on any server
4. as Mark pointed , JSPs are easy to use for larger files that has to render more HTML (its nightmare to write those escape sequnce in servlets to have HTML rendering) and we can take advantage of taglibs, struts etc newer and good concepts which are very useful...
5. its easier to have JSPs as most webservers now allow them updated without need to restart and this is good for debugging purposes. we can't do same with Servlets. we have to recompile servlets and restart the webserver everytime...(i don't know if any webserver allows JSP like enability for servlets as well)
any other points from anybody??
regards
maulin.
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
JSP's and servlets, in my opinion, should alway coexist. JSP's to render the presentation and servlets to control flow.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
i agree with william.
regards
maulin
 
wood burning stoves
 
subject: Diffrence between JSP and Servlets