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.

Explain the JSP while loop.

Answer»

The JSP While loop is USED to ITERATE the elements where it has one PARAMETER of the condition.

Syntax of While loop:

While(i<N){ //Block of statements}
2.

Explain the JSP for loop.

Answer»

The JSP For loop is used for ITERATING the elements for a certain CONDITION, and it has the following THREE parameters:

  • The variable counter is initialized
  • Condition till the loop has to be executed
  • The counter has to be incremented

The for loop syntax is as follows:

for(inti=0;i<n;i++){ //BLOCK of statements}
3.

What are JSP Operators?

Answer»

JSP Operators support most of the arithmetic and logical operators that are supported by java within expression language (EL) tags.

Following are the frequently used jsp operators:

.Access a bean property or MAP entry.
[]Access an ARRAY or List element.
()Group a subexpression to change the evaluation order.
+Addition
-Subtraction or negation of a value
*Multiplication
/ or divDivision
% or modModulo (remainder)
== or eqTest for equality
!= or neTest for inequality
< or ltTest for LESS than
> or gtTest for GREATER than
<= or leTest for less than or equal
>= or geTest for greater than or equal
&& or andTest for logical AND
|| or orTest for logical OR
! or notUnary Boolean complement
EmptyTest for empty variable VALUES
4.

What is JSP Expression Language (EL)?

Answer»

Expression LANGUAGE (EL) was introduced in JSP 2.0. It is a mechanism that simplifies the ACCESSIBILITY of the data stored in JAVABEAN COMPONENTS and other objects like request, session, and application, etc. There are many operators in JSP that are used in EL like arithmetic and logical operators to PERFORM an expression.

5.

What is the difference between JSP and Javascript?

Answer»

JSP is a server-side scripting language as it RUNS on the server. Whereas, JAVASCRIPT runs on the client. Commonly, JSP is more used to change the content of a webpage, and JavaScript for the presentation. Both are QUITE commonly used on the same page.

6.

What are the types of elements with Java Server Pages (JSP)?

Answer»

The three types of elements with Java Server Pages (JSP) are directive, action, and scripting elements.
Following are the Directive Elements:

ElementDescription
<%@ page ... %>Defines page-dependent attributes, such as scripting language, error page, and buffering requirements.
<%@ include ... %>Includes a file during the translation phase.
<%@ taglib ... %>Declares a tag library, containing custom actions, used on the page.

The Action elements are:

ElementDescription
<jsp:useBean>This is for making the JAVABEANS component available on a page.
<jsp:GETPROPERTY>This is used to get a property value from a JavaBeans component and to add it to the response.
<jsp:setProperty>This is used to set a value for the JavaBeans property.
<jsp:include>This includes the response from a servlet or JSP page during the request processing phase.
<jsp:forward>This is used to forward the processing of a request to a JSP page or servlet.
<jsp:param>This is used for adding a parameter value to a request given to another servlet or JSP page by using <jsp:include> or <jsp:forward>
<jsp:plugin>This is used to generate HTML that contains the proper client browser-dependent elements which are used to execute an APPLET with Java Plugin software.

And lastly, the Scripting elements are:

ElementDescription
<% ... %>Scriptlet used to embed scripting code.
<%= ... %>Expression, used to embed Java expressions when the RESULT shall be added to the response. Also used as runtime action attribute values.
<%! ... %>Declaration used to DECLARE instance variables and methods in the JSP page implementation class.
7.

Explain the Life Cycle of a servlet.

Answer»

A Java class that uses the Servlet Application Programming Interface (API) is a Servlet. The Servlet API consists of many CLASSES and interfaces that define some methods. These methods make it possible to process HTTP requests in a web server-independent manner.

A servlet is loaded when a web server receives a request that should be HANDLED by it. Once a servlet has been loaded, the same servlet INSTANCE (object) is called to process succeeding requests. Eventually, the webserver needs to shut down the servlet, typically when the web server itself is shut down. 

The 3 life cycle methods are:

  • public void INIT(ServletConfig config)
  • public void service(ServletRequest req, ServletResponse res)
  • public void destroy( )

These methods define the interactions between the web server and the servlet.

8.

What are Servlets?

Answer»

JSP PAGES are often combined with SERVLETS in the same application. The JSP specification is based on the Java SERVLET specification. Simply put, a servlet is a piece of code that adds new functionality to a web server, just LIKE CGI and proprietary server extensions such as NSAPI and ISAPI. Compared to other technologies, servlets have a number of advantages: 

  • Platform and vendor independence
  • Integration
  • Efficiency
  • Scalability
  • Robustness and security
9.

What is Java Server Template Engines?

Answer»

A Java servlet template engine is a technology for separating presentation from processing. Template engines have been developed as open-source PRODUCTS to help get HTML out of the servlets. These template engines are INTENDED to be used TOGETHER with pure code components (servlets) and use only web pages with SCRIPTING code for the presentation part.

Two popular template engines are WebMacro (http://www.webmacro.org) and FreeMarker (http://freemarker.sourceforge.net).

10.

What are some of the advantages of using JSP?

Answer»
  • Better performance and quality as JSP is a specification and not a product.
  • JSP pages can be used in combination with servlets.
  • JSP is an INTEGRAL part of J2EE, a COMPLETE PLATFORM for Enterprise-class applications.
  • JSP supports both scripting and element-based DYNAMIC content.
11.

What is the use of JSP?

Answer»

Earlier, Common Gateway Interface (CGI) was the only tool for developing dynamic web content and was not very efficient. The web server has to create a new operating system process, load an interpreter and a script, execute the script, and then tear it all down again, for EVERY request that comes in. This is taxing for the server and doesn’t scale well when the number of TRAFFIC increases.

Alternatives such as ISAPI from Microsoft, and JAVA Servlets from Sun Microsystems, offer better performance and scalability. However, they generate web PAGES by embedding HTML directly in programming language code. JavaServer Pages (JSP) changes all of that.

12.

How does JSP Initialization take place?

Answer»

When a CONTAINER loads a JSP, it invokes the jspInit() METHOD before SERVICING any requests.

public VOID jspInit(){ // Initialization code...}
13.

How does JSP work?

Answer»

The JSP container has a special servlet called the page compiler. All HTTP requests with URLs that match the .jsp file extension are forwarded to this page compiler by the configuration of the servlet container. The servlet container is turned into a JSP container with this page compiler. When a .jsp page is FIRST called, the page compiler parses and COMPILES the .jsp page into a servlet class. The JSP servlet class is loaded into memory on the successful compilation. For the subsequent calls, the servlet class for that .jsp page is already in memory. Hence, the page compiler servlet will always COMPARE the timestamp of the JSP servlet with the JSP page. If the .jsp page is more CURRENT, recompilation is necessary. With this process, once deployed, JSP PAGES only go through the time-consuming compilation process once.

14.

What is JSP?

Answer»

JSP stands for JAVA Server Pages. This technology is used to create dynamic web pages in the form of HyperText Markup Language (HTML). They have embedded Java code PIECES in them. They are an extension to the Servlet Technology and generate Servlet from a PAGE. It is common to use both servlets and JSP pages in the same web APPS.