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
Servlet | JSP | |
---|---|---|
1 | Servlet is faster than jsp | JSP is slower than Servlet because it first translate into java code then compile. |
2 | In 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. |
3 | Servlet is a java code. | JSP is tag based approach. |
4 | In 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. |
5 | To 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. |
6 | Coding of Servlet is harden than jsp. | Coding of jsp is easier than Servlet because it is tag based. |
7 | In 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. |
8 | Servlet accept all protocol request. | JSP will accept only http protocol request. |
9 | In Servlet, aervice() method need to override. | In JSP no need to override service() method. |
10 | In Servlet, by default session management is not enabled we need to enable explicitly. | In JSP, session management is automatically enabled. |
11 | In 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. |
12 | In 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. |
13 | In Servlet, all package must be imported on top of the servlet. | In JSP, package imported anywhere top, middle and bottom. |
Comments
Post a Comment