1.Explain JSP life Cycle methods?
- jsp engine controls the life cycle of jsp
- Jsp life cycle is described by three life cycle methods and six life cycle phases
Jsp life cycle methods :
- jspInit()
- _jspService()
- jspDestroy()
- Jspinit() method is invoked when JSP page is initialized.
- The _jspService() method corresponds to the body of the jsp page.
- This method is defined automatically by the JSp container and should never be defined y the JSP page author.
Jsp Life cycle Phases:
- Translation phase
- Compilation phase
- Instantiation phase
- initialization phase
- Servicing phase
- Destruction phase
Read More at : JSP Life Cycle
2. What are the Jsp Implicit Objects?
- Implicit objects in jsp are the objects that are created by the container automatically and the container makes all these 9 implicit objects to the developer.
- We do not need to create them explicitly, since these objects are created and automatically by container and are accessed using standard variables(objects) are called implicit objects.
- The following are of implicit variables available in the JSP.
- out
- request
- response
- config
- application
- session
- pagecontext
- page
- exception
3. Explain Jsp Scripting Elements?
- Jsp scripting elements are used to embed jva code in to the jsp.
- Jsp scripting elements are three types
- Declaration
- Expression
- Scriplet
4. What are the Directives in Jsp?
- A jsp directive is a translation time instruction to the jsp engine.
- we have three kinds of directives.
- Page directive
- Include directive
- Taglib directive
Read More at: Jsp Directive Elements
5. What are the differences between include directive and include action?
6. How to disable session in JSP?
- By using page directive
- <%@ page session="false" %>
7. How can we handle exceptions in a JSP page?
- We can handle exception in jsp by using error page element of page directive
- The errorPage attribute tells the JSP engine which page to display if there is an error while the current page runs.The value of the errorPage attribute is a relative URL.
The following directive displays MyErrorPage.jsp when all uncaught exceptions are thrown
Syntax:
errorPage="url"
Example:
<%@ page errorPage="error.jsp"%>
8.How can we override jspInit() and jspDestroy() methods in a jsp?
- Both methods are executed once in a life cycle of a jsp.
- We can override these two method as shown below.
- <%!
public void jspInit() {
. . .
}
%> - <%!
public void jspDestroy() {
. . .
}
%>
9.Can a JSP extend a java class?
- Yes we can extend a java class in jsp
- <%@ include page extends="classname" %>
- We can do this because jsp will convert to a servlet so a servlet can extend a class its fine
10.How can we pass information from one jsp to included jsp page?
- <jsp:include page="employeedetail.jsp" flush="true">
- <jsp:param name="name" value="abc"/>
- <jsp:param name="id" value="220"/>
No comments