hi , could any 1 pls tellme the diffrence between JSP and Servlets. When do you preffer one over the other. thanx, -a
Joined: Feb 14, 2001
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.
Joined: Nov 04, 2001
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.