Difference Between Servlet and JSP


Prev Tutorial Next Tutorial

Difference Between Servlet And JSP

When we need Servlet and JSP ?

For hug request processing logic with less response generation logic we need Servlet

With less request processing logic with more response generation logic we need JSP.

Problem with Servlet

If any changes in static html code of Servlet, the entire Servlet need recompilation, redeployment, needs server restart.

Any modification in Servlet needs recompilation because both request processing logic and response generation logic are tight coupled.

Difference Between Servlet and JSP

difference between servlet and jsp
ServletJSP
1Servlet is faster than jspJSP is slower than Servlet because it first translate into java code then compile.
2In Servlet, if we modify the code then we need recompilation, reloading, restarting the server> It means it is time consuming process.In JSP, if we do any modifications then just we need to click on refresh button and recompilation, reloading, restart the server is not required.
3Servlet is a java code.JSP is tag based approach.
4In Servlet, there is no such method for running JavaScript at client side.In JSP, we can use the client side validations using running the JavaScript at client side.
5To run a Servlet you have to make an entry of Servlet mapping into the deployment descriptor file i.e. web.xml file externally.For running a JSP there is no need to make an entry of Servlet mapping into the web.xml file externally, you may or not make an entry for JSP file as welcome file list.
6Coding of Servlet is harden than jsp.Coding of jsp is easier than Servlet because it is tag based.
7In MVC pattern, Servlet plays a controller role.In MVC pattern, JSP is used for showing output data i.e. in MVC it is a view.
8Servlet accept all protocol request.JSP will accept only http protocol request.
9In Servlet, aervice() method need to override.In JSP no need to override service() method.
10In Servlet, by default session management is not enabled we need to enable explicitly.In JSP, session management is automatically enabled.
11In Servlet we do not have implicit object. It means if we want to use an object then we need to get object explicitly form the servlet.In JSP, we have implicit object support.
12In Servlet, we need to implement business logic, presentation logic combined.In JSP, we can separate the business logic from the presentation logic by uses javaBean technology.
13In Servlet, all package must be imported on top of the servlet.In JSP, package imported anywhere top, middle and bottom.

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements