JSP Interview Questions
There is a list of top 40 frequently asked JSP interview questions and answers 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 a server-side programming language used to create a dynamic web page in the form of HyperText Markup Language (HTML). It is an extension to the servlet technology.
A JSP page is internally converted into the servlet. JSP has access to the entire family of the Java API including JDBC API to access enterprise database. Hence, Java language syntax has been used in the java server pages (JSP). The JSP pages are more accessible to maintain than Servlet because we can separate designing and development. It provides some additional features such as Expression Language, Custom Tags, etc.More details.
2) What are the life-cycle methods for a JSP?
3) List out some advantages of using JSP.
4) Give the syntax for JSP comments.
The syntax for JSP comments is:
5) What is the difference between hide comment and output comment?
The JSP comment is called hide comment whereas HTML comment is called output comment. If a user views the source of the page, the JSP comment will not be shown whereas HTML comment will be displayed.
6) What are the JSP implicit objects?
JSP provides nine implicit objects by default. They are as follows:
7) What is the difference between include directive and include action?
8) Is JSP technology extensible?
Yes. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.
9) 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.
10) How can I prevent the output of my JSP or Servlet pages from being cached by the browser?
(OR) How to disable caching on the back button of the browser?
11) 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 the web.xml file.More details.
12) What are the two ways to include the result of another page. ?
There are two ways to include the result of another page:
13) How can we forward the request from JSP page to the servlet?
Yes of course! With the help of "forward action" tag, but we need to give the URL-pattern of the servlet.forward action tag
14) 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.More details.
15) 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, and this data is then presented to the JSP for rendering on to the client.forward action tag
16) What are context initialization parameters?
Context initialization parameters are specified by the <context-param> in the web.xml file, and these are initialization parameter for the whole application and not specific to any servlet or JSP.More details.
17) What are the different scope values for the <jsp:useBean> tag?
There are 4 values:
18) What do JSP literals consist of?
19) What is the purpose of <jsp:useBean>?
The jsp:useBean action searches for the existence of the object with specified name. If not found, it creates one.
20) What is the purpose of <jsp:setProperty >?
This action sets the properties of a bean.
21) What is the purpose of <jsp:getProperty >?
This action retrieves the properties of a bean.
22) List out the various scope values of JSP action.
The possible scope values are:
23) What is the use of 'out' implicit object?
The object is used to give a response to contents.
24) Give the use of session object.
The object is used between the client requests for the tracking of client sessions.
25) Give the use of exception object.
The object is used for the generation of a response to the errors thrown.
26) What is the difference between ServletContext and PageContext?-
ServletContext gives the information about the container whereas PageContext gives the information about the Request.
27) What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
request.getRequestDispatcher(path) is used to create it we need to give the relative path of the resource whereas context.getRequestDispatcher(path)to create it we need to give the absolute path of the resource.
28) 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.
29) What are the primary differences between the JSP custom tags and java beans?
30) Can an interface be implemented in the JSP file?
31) What is JSTL?
JSP Standard Tag Library is a library of predefined tags that ease the development of JSP.More details.
32) How many tags are provided in JSTL?
There is 5 type of JSTL tags.
33) Which directive is used in JSP custom tag?
The JSP taglib directive.
34) What are the three tags used in JSP bean development?
35) How to disable session in JSP?
36) List the various action tags used in JSP.
Following are the list of various action tags used in JSP:
37) Explain the steps for creating custom tags in JSP?
For creating any custom tag, we need to follow the following steps:
38) How can the applets be displayed in the JSP? Explain with an example.
The jsp:plugin action tag is used to embed an applet in the JSP file. The jsp:plugin action tag downloads plugin at client side to execute an applet or bean.
Example of displaying applet in JSP
39) What is Expression language in JSP?
The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean component, and other objects like request, session, application.
There are many implicit objects, operators and reserve words in EL.
It is the newly added feature in JSP technology version 2.0.
40) Explain various implicit objects in expression language.