Servlet | JSP |
Servlets run faster than JSP. | JSP runs slower than servlet as it takes time to compile the program and convert into servlets. |
It is hard to write code in servlet. | It’s easier to code in JSP compared to servlets. |
In MVC architecture, servlet works as a controller. | In MVC architecture, JSP works as a view for displaying output. |
There is no custom tag writing facility in servlets. | You can easily build custom tags that can directly call Java beans. |
Servlet is a java code. | JSP is a HTML-based code. |
In Servlet, you have to implement both business logic and presentation logic in the single file. | In JSP, business logic is split from presentation logic using JavaBeans. |
Let us start the JSP programming with a simple program to show “Hello World” on a jsp page.
welcome.jsp
<html> <head> <title>Welcome</title> </head> <body> <h1>Hello World.</h1> </body> </html> |
web.xml
<web-app> <welcome-file-list> <welcome-file>welcome.jsp</welcome-file> </welcome-file-list> </web-app> |