different between Servlet & JSP2

1) The first and foremost difference between Servlet and JSP is that a JSP is a web page scripting language that can generate dynamic content while Servlets are Java programs that are already compiled which also creates dynamic web content.

2) The second difference between Servlet vs JSP is that JSP is actually translated and compiled into Servlet by web container when the first request comes for it, on the other hand, Servlet is already a Java program, whose instance is created and managed by the web container.

3) Since JSP is translated and compiled into Servlet, they run faster compared to JSP.

4) JSP was designed for HTML developer who doesn't know Java but familiar with the tag-based markup language like HTML, while Servlet is designed for Java developers who like to code in Java.

5) In MVC design pattern, JSP (Java Server Pages) act as a view and servlet act as a Controller.

6) JSP are generally preferred when there is not much processing of data required. But Servlets are best for use when there are more processing and manipulation involved. Your JSP should be as dumb as possible i.e. it should not contain any logic, all logic should go to Servlets. The job of JSP should just to display the data provided via model to it. If your JSP starts containing logic then it would be difficult to maintain.

7)The advantage of JSP programming over Servlet is that we can build custom tags which can directly call Java beans. There is no such facility in servlets. On the other JSTL is the popular tag library which allows you to completely remove Java from JSP. By using expression language and JSTL core tag library, you can make your JSP free of Java.

8) We can achieve the functionality of JSP at the client side by running JavaScript at client side. There are no such methods for servlets.

Last updated