Skip to main content

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.

Comments

Popular posts from this blog

Mockito interview Questions

1.       Question 1. What Is Mockito? Answer : Mockito allows creation of mock object for the purpose of Test Driven Development and Behavior Driven development. Unlike creating actual object, Mockito allows creation of fake object (external dependencies) which allows it to give consistent results to a given invocation. 2.       Question 2. Why Do We Need Mockito? What Are The Advantages? Answer : Mockito differentiates itself from the other testing framework by removing the expectation beforehand. So, by doing this, it reduces the coupling. Most of the testing framework works on the "expect-run-verify". Mockito allows it to make it "run-verify" framework. Mockito also provides annotation which allows to reduce the boilerplate code. 3.       Question 3. Can You Explain A Mockito Framework? Answer : In Mockito, you always check a particular class. The dependency in that class is injected using m...

REST Methods

GET ============================================= HTTP GET method is used to **read** (or retrieve) a representation of a resource. According to the design of the HTTP specification, GET requests are used only to read data and not change it. Therefore, when used this way, they are considered safe. That is, they can be called without risk of data modification or corruption. Means calling it once has the same effect as calling it 10 times. Additionally, GET is idempotent which means that making multiple identical requests ends up having the same result as a single request. Donot expose unsafe operations via GET. It should never modify any resources on the server. Example: ------------    GET http://www.example.com/customers/12345/orders POST =================================== -> The POST verb is most-often utilized to **create** new resources. In particular, it's used to create subordinate resources. -> That is, subordinate to some other (e.g. parent) reso...