Advanced Java Programming - Old Questions
9. What is JSP? Differentiate it with servlet. (2+3)
Java Server Pages (JSP) is server side technology to create dynamic java web application. It allows
java programming code to be embedded in the HTML pages.
-
Scripting elements are used to provide
dynamic pages.
- JSP simply puts Java inside HTML pages.
Servlets |
JSP |
Servlet is a pure java code. |
JSP is a tag based approach. |
We write HTML in servlet code. |
We write JSP code in HTML. |
Servlet is faster than JSP. |
JSP is slower than servlet
because it first translate into java code then compile. |
Writing
code for servlet is harder than JSP as it is html in java. |
JSP
is easy to code as it is java in html. |
Servlet
can accept all protocol requests. |
JSP
only accept http requests. |
Modification
in Servlet is a time consuming task because it includes reloading,
recompiling and restarting the server. |
JSP
modification is fast, just need to click the refresh button. (reloading,
recompilation and restart the server is not required) |
Servlets do not have implicit
objects. |
JSP does have implicit objects. |
In
Servlet, we can override the service() method. |
In
JSP, we cannot override its service() method. |
In MVC pattern, servlet act as a
controller. |
In MVC, JSP act as a view. |
In Servlet, by default session
management is not enabled we need to enable explicitly. |
In JSP, session management is
automatically enabled. |
Packages are to be imported at
the top of the servlet. |
Packages can be imported anywhere
in the JSP code. |