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...

JAVA Expert Interview Questions Answers 2017

Java Basics ::  Interview Questions and Answers Home  »  Interview Questions  »  Technical Interview  »  Java Basics  » Interview Questions 1.     What is the difference between a constructor and a method? A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. 2.     What is the purpose of garbage collection in Java, and when is it used? The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. 3.  ...

Java Example Program to Convert List to Set

import java.util.ArrayList; import java.util.HashSet; import java.util.Set; public class ListToSet {  /**   * @author Amarjit Kumar   * @category interview questions   *   * Description: Convert List to set in java with example program   *   */  public static void main(String[] args) {   ArrayList<String> arrList= new ArrayList<>();   arrList.add("Java");   arrList.add("Java");   arrList.add("List to String");   arrList.add("Example Program");   Set<String> strSet = new HashSet<String>(arrList);   System.out.println(strSet);   System.out.println(arrList);  } } /*  * Java program to convert list to set. Convert ArrayList of string to HashSet  * in java example program How to convert List to Set in java Set<String> strSet  * = new HashSet<String>(arrList); HashSet having a constructor which will take  * list as an ar...