There is a list of 25 jsp interview questions for freshers and professionals. If you know any jsp interview question that has not been included here, post your question in the Ask Question section.
1)What is JSP?
Java Server Pages technology (JSP) is used to create dynamic web page. It is an extension to the servlet technology. A JSP page is internally converted into servlet.
2) What are the life-cycle methods for a jsp?
|public void jspInit()||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.|
3)What is difference between hide comment and output comment?
The jsp comment is called hide comment whereas html comment is called output comment. If user views the source of the page, the jsp comment will not be shown whereas html comment will be shown.
4)What are the JSP implicit objects ?
JSP provides 9 implicit objects by default. They are as follows:
5)What is difference between include directive and include action?
|include directive||include action|
|1) The include directive includes the content at page translation time.||1) The include action includes the content at request time.|
|2) The include directive includes the original content of the page so page size increases at runtime.||2) The include action doesn’t include the original content rather invokes the include() method of Vendor provided class.|
|3) It’s better for static pages.||3) It’s better for dynamic pages.|
6) Is JSP technology extensible?
Yes. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.
7) How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?
You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe=”false” %> within your JSP page.
8) How can I prevent the output of my JSP or Servlet pages from being cached by the browser?
(OR) How to disable caching on back button of the browser?
- response.setHeader (“Expires”, “0”); //prevents caching at the proxy server
9) How can we handle the exceptions in JSP ?
There are two ways to perform exception handling, one is by the errorPage element of page directive, and second is by the error-page element of web.xml file.
10) What are the two ways to include the result of another page. ?
There are two ways to include the result of another page:
- By include directive
- By include action
11) How can we forward the request from jsp page to the servlet ?
Yes ofcourse! With the help of forward action tag, but we need to give the url-pattern of the servlet.
forward action tag
12) Can we use the exception implicit object in any jsp page ?
No. The exception implicit object can only be used in the error page which defines it with the isErrorPage attribute of page directive.
13) How is JSP used in the MVC model?
JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client.
forward action tag
14) What are context initialization parameters?
Context initialization parameters are specified by the <context-param> in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP.
15) What are the different scope values for the <jsp:useBean> tag?
There are 4 values:
16)What is the difference between ServletContext and PageContext?-
ServletContext gives the information about the container whereas PageContext gives the information about the Request.
17)What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
request.getRequestDispatcher(path) is used in order to create it we need to give the relative path of the resource whereas context.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.
18) What is EL in JSP?
The Expression Language(EL) is used in JSP to simplify the accessibility of objects. It provides many objects that can be used directly like param, requestScope, sessionScope, applicationScope, request, session etc.
19)What is basic differences between the JSP custom tags and java beans?
- Custom tags can manipulate JSP content whereas beans cannot.
- Complex operations can be reduced to a significantly simpler form with custom tags than with beans.
- Custom tags require quite a bit more work to set up than do beans.
- Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
20) Can an interface be implemented in the jsp file ?
21) What is JSTL?
JSP Standard Tag Library is library of predefined tags that ease the development of JSP.
22) How many tags are provided in JSTL?
There are 5 type of JSTL tags.
- core tags
- sql tags
- xml tags
- internationalization tags
- functions tags
23) Which directive is used in jsp custom tag?
The jsp taglib directive.
24) What are the 3 tags used in JSP bean development?
25) How to disable session in JSP?
- <%@ page session=“false” %>