JSP Interview Questions and Answers

Last update: 08 Mar 2022, 22 Questions

JavaServer Pages or JSP is a software-based technology that helps developers in creating dynamically generated web pages based on XML or HTML. It uses servlet containers, small programs to control the content and appearance of the web page. JSP technology can also be used to share information across pages using a response and request objects. With the help of JavaServer Page, you can easily access JavaBeans objects and make a separation in the web applications as per the business logic. To know more about JavaServer Page, we are mentioning some of the JSP Interview Questions are useful for all types of readers.

Most Frequently Asked JSP Interview Questions

Here in this article, we will be listing frequently asked JSP Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

1. What is JSP and why it is used?

JSP or JavaServer Pages is a software technology used to develop to dynamic interactive web pages based on HTML or XML while controlling the content or appearance of web pages with the use of servlet containers. It has s wide a range of applications and separates business logic from the presentation layer.

4 1
2. What is the difference between include directive and include action?

Here are a few crucial differences between these two:

  • Include directive is processed at the translation time, but include action is processed at the request time.
  • Include directive uses both absolute and relative path, whereas include action only uses a relative path.
  • Include directive only uses the contents of the resource, while include action process dynamic content resource.
2 0
3. What are the advantages of JSP?

Using JSP has numbers of benefits, such as

  • It allows tag-based programming
  • Suitable for both Java and non-Java programmers
  • Allows developers to use separate presentation logic
  • Highly increases readability of code because of tags
  • Easy to learn and apply
0 1
4. What do you mean by JSP Directives?

These are the messages to JSP container, and they provide global information for an entire JSP page. JSP directives are used by developers to give special instruction to a container for translation of JSP to servlet code. These directives can contain many attributes by comma separated as key-value pairs. JSP directives are described in <%@ %> tags.

0 0
5. How do you enable and disable sessions using JSP?

The session in a JSP page can be disabled by setting the session attributes to false. The following can be exampled to disable the session object using page directive: <%@ page session="false" %>

0 0
6. What do you mean by Custom Tag in JSP?

A JSP custom tag is a user-defined JSP language element. A JSP page which contains a custom tag is generally transcribed into a servlet. Then, the custom tag is converted to operations on an object called a tag handler. The custom tags can be created with JSP tag extensions that let developers insert these new tags directly into a JSP.

0 0
7. What is the difference between servlet and JSP?

JSP is a dynamic content generating webpage scripting language, whereas servlets are programs that operate on a web or application server and act as a middle layer between a request coming from applications on the HTTP server, or a web browser or other HTTP client and database.

0 0
8. Explain JSP lifecycle methods?

The JSP lifecycle methods are as following:

  • jspInit() : It operates to initialize the servlet instance. Before calling any other method, its call is made.
  • _jspService() : It passes the request and the response subjects. You can’t override the method.
  • jspDestroy(): The container calls this when its instance is about to destroy.
0 0
9. What are different types of comments used in JSP?

Basically, there are two types of comments allowed in the JSP, hidden comments and output comments.


The hidden comments of JSP don’t appear in the generated output in the HTML (ex: <%-- This is hidden comment --%>), while output comments arrear in the generated output ex: <!-- This is output comment -->).

0 0
10. Define Scriptlet, Expression and Declaration in JSP?

A JSP expression is used to put the Java values directly into the output. It has the form of <%= Java expression %>. JSP scriptlets are more than the simple expression and used to insert complex code into the service() method of the generated servlet. Whereas, a JSP declaration defines fields or methods that get inserted into the main body of the servlet class.

0 0
11. Explain the JSP implicit objects?

Created by JSP Engine during translation phase, while translating JSP to Servlet, JSP implicit objects are crafted inside service method and can be used directly within scriptlet without initializing and declaring them. In JSP, a total number of 9 implicit objects are available as following, Out, Request, Response, Session, Application, Exception, Page, pageContext, and config.

0 0
12. How we can include the result of another page in JSP?

So many mechanisms are available through which the results of another page can be included in JSP.

There of primary mechanisms used by developers are

  • Include directive
  • jsp:include element
  • Codas and preludes
0 0
13. List the different scope values for the <jsp:useBean> tag in JSP?

This tag is required to use any Java object present in the JSP page.

The scope values for tag are as following: application, request, page, session, etc.

0 0
14. What is <jsp:useBean> in JSP?

This action tag is used to instantiate or locate a bean class. Depending on the scope, it doesn’t create the bean if the bean object of the Bean class is already created. This JSP action tag has five attributes, which includes Id, Scope, Class, Type and Bean Name.

0 0
15. What are the difference between ServletContext and PageContext?

In JSP, the ServletContext shares information about the container in which the servlet is running in. This can be set up in the web application descriptor. There can be only one v ServletContext per web application. Compared to this, the PageContext gives the servlet information about the request that it is currently managing and contains information about the request, the response object, the session, and also a reference to the ServletContext of the web application.

0 0
16. What is the differences between the JSP custom tags and java beans?
  • Custom tags are used to manipulate the JSP content, whereas Java beans can’t be manipulated.
  • Java beans are easy to implement compared to custom tags which are tedious to implement.
  • Custom tags contain self-contained behaviour, but Java beans are defined in one servlet and it is used in the JSP page or different servlet.
0 0
17. What do you mean by JSTL? The JSP Standard Tag Library or JSTL is a set of tags created to simplify the JSP development. The JSTL tags help in fast development, code reusability and eliminate the required use of scriptlet tags.
0 0
18. List all tags that are provided in JSTL?

Based on function, JSTL tags are categorized into five types, which are Core Tags, Formatting and Localisation Tags, SQL Tags, XML Tags and Functions Tags.

0 0
19. What are the steps for creating custom tags in JSP?

To create a custom tag in JSP, use the following steps.

  • Create the tag handler class first
  • Then, create the TLD file
  • Finally, create the JSP file
0 0
20. How we can configure init params in JSP?

Developers can configure init params in JSP similar to the servlet in the web.xml file. We have to configure JSP init-params with servlet and servlet-mapping element. Put the JSP page location in the JSP-file element.

0 0
21. What are the difference between JspWriter and Servlet PrintWriter?

JSP PrintWriter is object directly responsible for writing the content in response, whereas JspWriter uses the PrintWriter object behind the scene while offering buffer support. After the buffer support is flushed or full, JspWriter uses the object in PrintWriter to write the content into a response.

0 0
22. How we can use JavaScript with JSP Pages?

As JavaScript is client-side script and JSP is a server-side script, developers can attach a form validation to a JSP page to redirect JavaScript content and HTML page.

0 0
Development History

Developed and released by Sun Microsystems in 1999, JSP is similar to ASP and PHP, it uses the Java programming language for its workability. A compatible web server with a servlet container, such as Jetty or Apache Tomcat, is required to run JSP.

The program actually runs with a .jsp filename extension and application/JSP internet media type. The latest version of JSP is its 2.3 version which runs with a 4.0 version of servlet compatibility.

These JSP interview questions are specially curated highly experienced industry professionals to help candidates in their future job success.

Advantages of JSP
  • Significant performance due to the allowance of embedding Dynamic Elements in HTML Pages.
  • Easily combined with static templates, XML or HTML fragments, with code that generate dynamic contents.
  • Web authors cab change or edit the fixed template portions of web pages without affecting the application logic.
  • It offers a wide range of API to highly increase the result-oriented functionality.
About Best Interview Question
Best Interview Question
Technical Consultant

With our 10+ experience in PHP, MySQL, React, Python & more our technical consulting firm has received the privilege of working with top projects, 100 and still counting. Our team of 25+ is skilled in distinct programming languages such as Python, Java, React.js, Angular, Node.js, PHP, HTML, CSS, Designing, iOS and Android apps, Database, .net, QA, Digital Marketing and Govt. jobs, etc. We are helping 10+ companies in solving their technical problems. When not found coding, our technical consultants can be seen helping out others.