JSP – Core Java Interview Questions
Modified Date:- Published Date:-Categories: Others
Q.1. What are the different tags provided in JSTL?
Ans. There are 5 type of JSTL tags.
(i) core tags
(ii) sql tags
(iii) xml tags
(iv) internationalization tags
(v) functions tags
Q.2. How to disable session in JSP?
Ans. <%@ page session=“false” %>
Q.3. Explain the jspDestroy() method.
Ans. jspDestry() method is invoked from javax.servlet.jsp.JspPage interface whenever a JSP page is about to be destroyed. Servlets destroy methods can be easily overridden to perform cleanup, like when closing a database connection.
Q.4. How is JSP better than Servlet technology?
Ans. JSP is a technology on the server’s side to make content generation simple. They are document-centric, whereas servlets are programs. A Java server page can contain fragments of Java program, which execute and instantiate Java classes. However, they occur inside an HTML template file. It provides the framework for the development of a Web Application.
Q.5. Why should we not configure JSP standard tags in web.xml?
Ans. We don’t need to configure JSP standard tags in web.xml because when container loads the web application and find TLD files, it automatically configures them to be used directly in the application JSP pages. We just need to include it in the JSP page using taglib directive.
Q.6. How will you use JSP EL in order to get the HTTP method name?
Ans. Using pageContext JSP EL implicit object you can get the request object reference and make use of the dot operator to retrieve the HTTP method name in the JSP page. The JSP EL code for this purpose will look like ${pageContext.request.method}.
Q.7. What are the differences between get and load methods?
Ans. The differences between get() and load() methods are given below.
No. |
get() |
load() |
1) |
Returns null if object is not found. |
Throws ObjectNotFoundException if an object is not found. |
2) |
get() method always hit the database. |
load() method doesn't hit the database. |
3) |
It returns a real object, not a proxy. |
It returns a proxy object. |
4) |
It should be used if you are not sure about the existence of instance. |
it should be used if you are sure that the instance exists. |
Q.8. What are the life-cycle methods for a jsp?
Ans.
Methods |
Description |
public void jsplnit() |
It is invoked only once, same as init method of servlet. |
public void _jspservice(ServletRequest request,ServletResponse)throws ServletException, IOException |
It is invoked at each request, same as service() method of servlet. |
public void jspDestroy() |
It is invoked only once, same as destroy() method of servlet. |