Tuesday, October 11, 2005

Difference between JSP and Servlets


The JSP engine(Jasper) essentially parses the JSP file to create a Java program (servlet), and compiles and runs it just like any other servlet. So the way servlet and jsp work is almost similar.

JSP's and servlets, should always coexist. JSP's to render the presentation and servlets to control flow. It is always better to have Business Logic in separate Java class(POJO’s) (or) EJB’s (or) Java Beans and use Servlets as controller between the Model and View. In a well designed J2EE web application, you should find little or no HTML in the servlets, and little or no Java in the JSP's.

Coming to when to use servlet or jsp. when your purpose is to render page at user end go for jsp, else if your purpose is to do some server side stuff such has database updatation, interacting with model and retrieving some data to pass it to JSP etc. go for servlet.

JSP has access to things like Tag libraries and JSTL which are not available in Servlets. Some of these features can be accomplished in other ways in Servlets, but not all.

Performance

The JSP will require to be translated and compiled into a servlet -- so on the first request the JSP will definitely be slower. But after that they should perform similarly (both are servlets).

1 Comments:

Blogger Rod Pendergrass said...

I enjoyed reading some of your posts. I have a psychic love reading site. It has psychic love reading related info as well as astrology, numerology, and tarot card readings to help you find your soul mate or lost loved one. Come and check it out if you get time :-)
Rod

4:00 AM  

Post a Comment

<< Home