Documente Academic
Documente Profesional
Documente Cultură
JSP stands for JavaServer Pages. JSP is java server side technology to create dynamic web
pages. JSP is extension of Servlet technology to help developers create dynamic pages with
HTML like syntax.
We can create user views in servlet also but the code will become very ugly and error prone.
Also most of the elements in web page is static, so JSP page is more suitable for web pages. We
should avoid business logic in JSP pages and try to use it only for view purpose. JSP scripting
elements can be used for writing java code in JSP pages but its best to avoid them and use JSP
action elements, JSTL tags or custom tags to achieve the same functionalities.
One more benefit of JSP is that most of the containers support hot deployment of JSP pages.
Just make the required changes in the JSP page and replace the old page with the updated jsp
page in deployment directory and container will load the new JSP page. We dont need to
compile our project code or restart server whereas if we make change in servlet code, we need
to build the complete project again and deploy it. Although most of the containers now provide
hot deployment support for applications but still its more work that JSP pages.
1.Translation JSP container checks the JSP page code and parse it to
generate the servlet source code. For example in Tomcat you will find
generated servlet class files
atTOMCAT/work/Catalina/localhost/WEBAPP/org/apache/jsp directory. If
the JSP page name is home.jsp, usually the generated servlet class name is
home_jsp and file name is home_jsp.java
2.Compilation JSP container compiles the jsp class source code and produce
class file in this phase.
3.Class Loading Container loads the class into memory in this phase.
4.Instantiation Container invokes the no-args constructor of generated class
to load it into memory and instantiate it.
5.Initialization Container invokes the init method of JSP class object and
initializes the servlet config with init params configured in deployment
descriptor. After this phase, JSP is ready to handle client requests. Usually from
translation to initialization of JSP happens when first request for JSP comes but
we can configure it to be loaded and initialized at the time of deployment like
servlets using load-on-startup element.
6.Request Processing This is the longest lifecycle of JSP page and JSP page
processes the client requests. The processing is multi-threaded and similar to
servlets and for every request a new thread is spawned and ServletRequest and
ServletResponse object is created and JSP service method is invoked.
7.Destroy This is the last phase of JSP lifecycle where JSP class is unloaded
from memory. Usually it happens when application is undeployed or the server
is shut down.
1.What are JSP lifecycle methods?
JSP lifecycle methods are:
Ans: This is a fact based interview question what it checks is how much coding you do in JSP if you are doing
it frequently you definitely know them. Implicit object are the object that are created by web container
provides to a developer to access them in their program using JavaBeans and Servlets. These objects are
called implicit objects because they are automatically instantiated.they are bydefault available in JSP page.
They are: request, response, pageContext, session, and application, out, config, page, and exception.