Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is a JSP Declaration?

Answer»

The TAGS used in declaring variables are called JSP Declaration tags. These are used in declaring FUNCTIONS and variables. They are enclosed in <%!%> tag. Following is the syntax for JSP Declaration:

<%@page contentType=”text/html” %><html><body><%!int a=0;private int getCount(){a++;RETURN a;}%><p>Values of a are:</p><p><%=getCount()%></p></body></html>
2.

What is MVC in JSP?

Answer»

In MVC,

  • M stands for Model
  • V stands for View
  • C stands for the controller.

It is an architecture that separates business LOGIC, presentation, and data. In this, the flow STARTS from the view layer, where the request is raised and processed in the controller layer. This is then SENT to the model layer to INSERT data and get back the success or failure message.

3.

What is the JSP Scriptlet?

Answer»

The JSP Scriptlet tag allows you to write Java code into a JSP file. The JSP container moves statements in the _jspservice() method while generating servlets from JSP.

For each REQUEST of the client, the service method of the JSP gets invoked hence the code inside the Scriptlet executes for EVERY request.

In Scriptlet, a java code is EXECUTED every time the JSP is invoked.

Syntax of Scriptlet tag:

&LT;% java code %>

Here <%%> tags are scriptlet tags and within it, we can place the java code.

4.

What are the various action tags used in JSP?

Answer»

Various action tags used in JSP are as follows:

  • jsp:FORWARD: This action tag forwards the request and response to another resource.
  • jsp:include: This action tag is used to include another resource.
  • jsp:USEBEAN: This action tag is used to create and locates bean objects.
  • jsp:setProperty: This action tag is used to set the value of the PROPERTY of the bean.
  • jsp:getProperty: This action tag is used to print the value of the property of the bean.
  • jsp:plugin: This action tag is used to embed another component such as the applet.
  • jsp:param: This action tag is used to set the parameter value. It is used in forward and includes mostly.
  • jsp:fallback: This action tag can be used to print the message if the plugin is WORKING.
5.

Explain the anatomy of a JSP page?

Answer»

Different JSP elements are used for generating the parts of the page that DIFFER for each request. A JSP page is a regular web page with different JSP elements. The three types of elements with JavaServer Pages are directive, action, and SCRIPTING elements. JSP elements are often used to work with JavaBeans.

The elements of the page that are not JSP elements are simply called the “template text”. The template text is commonly HTML, but it could also be any other text.

When a page request of JSP is PROCESSED, the template text and the dynamic content GENERATED by the JSP elements are merged, and the RESULT is sent as the response to the browser.

6.

How does JSP processing take place?

Answer»

The JSP page is TURNED into a servlet for all the JSP elements to be processed by the server. Then the servlet is executed. The servlet container and the JSP container—are OFTEN combined into one package under the name “web container”.

In the translation phase, the JSP container is responsible for converting the JSP page into a servlet and COMPILING the servlet. This is used to automatically initiate the translation phase for a page when the first request for the page is received.

In the “request processing” phase, the JSP container is also responsible for INVOKING the JSP page implementation class to process each request and GENERATE the response.

7.

What is an Exception Object?

Answer»

The exception object is an instance of a subclass of THROWABLE (e.g., java.lang. NullPointerException). It is only available on the error pages. The following table lists out the important methods available in the Throwable class: 

1public String getMessage()
Returns a detailed message about the exception that has occurred. This message is initialized in the Throwable constructor.
2public Throwable getCause()
Returns the cause of the exception as represented by a Throwable object.
3public String toString()
Returns the name of the class concatenated with the result of getMessage().
4public void printStackTrace()
PRINTS the result of toString() ALONG with the stack trace to System.err, the error output stream.
5public StackTraceElement [] getStackTrace()
Returns an array containing each element on the stack trace. The element at INDEX 0 represents the top of the call stack, and the last element in the array represents the method at the bottom of the call stack.
6public Throwable fillInStackTrace()
Fills the stack trace of this Throwable object with the CURRENT stack trace, adding to any previous information in the stack trace.
8.

Which methods are used for reading form data using JSP?

Answer»

JSP is used to handle the FORM data parsing automatically. It DIES so by using the following METHODS depending on the situation:

  • getParameter() − To get the value of a form PARAMETER, call the request.getParameter() method.
  • getParameterValues() − If a parameter appears more than once and it returns multiple values, call this method.
  • getParameterNames() − This method is used if, in the current request, you want a complete LIST of all parameters.
  • getInputStream() − This method is used for reading binary data streams from the client.
9.

What are JSTL Core tags used for?

Answer»

The JSTL Core TAGS are used for the FOLLOWING purposes:

  • Iteration
  • Conditional logic
  • Catch exception
  • URL forward
  • Redirect, etc.

Following is the syntax to INCLUDE a tag library:

&LT;%@ taglib prefix="c" uri=http://java.sun.com/jsp/jstl/core%>
10.

What is JSTL?

Answer»

JSTL stands for Java server pages standard tag library. It is a collection of custom JSP tag libraries that provide common functionality for web development.

Following are some of the properties of JSTL:

  • Code is Neat and Clean.
  • Being a Standard Tag, it provides a RICH layer of the portable functionality of JSP pages.
  • It has Automatic JAVABEANS Introspection Support. The JSTL Expression language handles JavaBean code very easily. We don't need to DOWNCAST the objects, which have been retrieved as SCOPED attributes.
  • Easier for humans to read and easier for COMPUTERS to understand.
11.

What do you mean by JavaBeans?

Answer»

JAVABEANS component is a Java class that COMPLIES with CERTAIN coding conventions. JSP elements OFTEN work with JavaBeans. For INFORMATION that describes application entities, JavaBeans are typically used as containers.

12.

What are Implicit JSP Objects?

Answer»
VARIABLE NameJava TypeDescription
requestjavax.servlet.http.HttpServletRequestThe request OBJECT is used to request information like a parameter, header information, server name, etc.
responsejavax.servlet.http.HttpServletResponseThe response is an instance of a class that represents the response that can be given to the CLIENT
pageContextjavax.servlet.jsp.PageContextThis is used to get, set, and REMOVE the attributes from a particular scope.
sessionjavax.servlet.http.HttpSessionThis is used to get, set, and remove attributes to session scope and also used to get session information.
applicationjavax.servlet.ServletContextThis is used to get the context information and attributes in JSP.
outjavax.servlet.jsp.JspWriterThis is an implicit object, used to write the data to the buffer and SEND output to the client in response.
configjavax.servlet.ServletConfigConfig is used to get the initialization parameter in web.xml
pagejava.lang.ObjectThis implicit variable holds the currently executed servlet object for the corresponding JSP.
exceptionjava.lang.ThrowableException which is the implicit object of the throwable class is used for exception handling in JSP.