JSP interview questions [ Part 2 ]

1. Use of page implicit object?

The page implicit object is of type Object and it is assigned a reference to the servlet that executing the _jspService() method. Page is the instance of the JSP page's servlet processing the current request. Not typically used by JSP page authors. Thus in the Servlet generated by tomcat the page object is created as
Object page = this;
Since page is a variable of type Object, it cannot be used to directly call the servlet methods. To access any of the methods of the servlet through page it must be first cast to type Servlet.
<%= this.getServletInfo(); %>
<%= ((Servlet)page).getServletInfo(); %>
But the following code will generate error, because can not use page directly without casting:
<%= page.getServletInfo(); %>
Note that page is not the same as the pageContext object

2. Use of application implicit object?
In JSP, application is an implicit object of type ServletContext.
The instance of ServletContext is created only once by the web container when application or project is deployed on the server.
This object can be used to get initialization parameter from configuaration file (web.xml). It can also be used to get, set or remove attribute from the application scope.
This initialization parameter can be used by all jsp pages.
3. Can we use JSP implicit objects in JSP Declaration?
4. Which implicit object is not available in normal JSP pages?
JSP exception implicit object is not available in normal JSP pages and it?s used in JSP error pages only to catch the exception thrown by the JSP pages and provide useful message to the client.

5. What are the benefits of PageContext implicit object?

6. How do we configure init params for JSP?
7. What is difference between include directive and jsp:include action?

8. What is JSP Expression Language and what are it?s benefits?
The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean component, and other objects like request, session, application etc.
There are many implicit objects, operators and reserve words in EL.
9. What are JSP EL implicit objects and how it?s different from JSP implicit Objects?

10. How do we print ?<br> creates a new line in HTML? in JSP?
We can use c:outescapeXml attribute to escape the HTML elements so that it get?s shown as text in the browser, for this scenario we will write code like below.
<c:out value="<br> creates a new line in HTML" escapeXml="true"></c:out>

11. What is jsp­config in deployment descriptor?

12. How to ignore the EL expression evaluation in a JSP?
We can deactivate EL evaluation in a single JSP page by specifying the attribute isELIgnored=?true? in the page directive as follows:
<%@ page isELIgnored="true" %>

Related Post