JSP Interview Questions And Answers

36 JSP Interview Questions And Answers – Java Server Pages Interview Questions For Experienced from Codingcompiler. Test your JSP knowledge by answering these tricky interview questions on JSP. Let’s start learning JSP interview questions and prepare for JSP interviews. All the best for your future and happy learning.

Table of Contents

JSP Interview Questions

  1. What is jsp and why is it needed?
  2. Tell us about the stages (phases) of the jsp life cycle.
  3. Tell us about the jsp life cycle methods.
  4. What JSP lifecycle methods can be overridden?
  5. How can I prevent direct access to a JSP page from a browser?
  6. How to comment out jsp code?
  7. Explain Scriptlet, Expression and Declaration in JSP.
  8. What are the implicit, internal objects and methods on the jsp page?
  9. Why are implicit objects not available in a regular JSP page?
  10. What do you know about PageContext and what are the advantages of using it?
  11. How to configure init parameters for JSP?
  12. Why is it not recommended to use script elements in jsp?
  13. Can we define a class inside a JSP page?
  14. What are the ways to insert java code into jsp page?
  15. How can I prevent the use of scripts and java code on the jsp page?
  16. What do you know about jsp tags? Explain how you understand the Action tag and JSP Action Elements.
  17. What is the difference between include and jsp directive: include action?
  18. What do you know about jsp expression language (JSP Expression Language – EL)?
  19. What are the implicit, internal EL JSP objects and their differences from jsp objects?
  20. How to find out the name of the http method using JSP EL?
  21. What is JSTL (Jsp Standard tag library)?
  22. Which categories can be divided JSTL tags, give examples.
  23. What do you know about writing custom jsp tags?
  24. Give an example of using your own tags.
  25. Why is it not necessary to configure standard JSP tags in web.xml?
  26. How can I handle jsp page errors?
  27. How does error handling occur with jstl?
  28. How to make a “new line in HTML” in JSP?
  29. Give a sample JSP configuration in the deployment descriptor.
  30. How to deactivate EL usage on JSP?
  31. When does a container initialize multiple JSP / Servlet objects?
  32. Can i use javascript on jsp page?
  33. Is the session object always created on the jsp page, is it possible to disable its creation?
  34. What is the difference between a JspWriter and a Servlet PrintWriter?
  35. How can I extend the functionality of jsp?
  36. Best Practices in JSP.

JSP Interview Questions And Answers

1. What is jsp and why is it needed?

JSP is JavaServer Pages. JSP is a server technology for creating dynamic web pages. JSP extends servlet technology to help developers create dynamic HTML pages with a similar syntax.

Creating views is also supported in servlets, but in this case, the code looks terrible and error prone. It was also noted that most of the elements of a web page are static and therefore the JSP page is more suitable for web pages. If possible, you should avoid business logic on the JSP page and use the page only as a presentation. Therefore, it is recommended to use JSP actions elements or JSTL tags instead of writing JSP scripts.

Another advantage to JSP is hot deployments. We can replace the old page with another one in the container and users will see the new JSP page. Thus, there is no need to compile the entire project or restart the server to update part of the pages.

2. Tell us about the stages (phases) of the jsp life cycle.

If you look at the code inside the created JSP page, it will look like HTML and will not look like a java class. JSP pages are converted into HTML code by a container that also creates a servlet for use in a web application. A JSP life cycle consists of several phases:

    1. Translation – JSP container checks the JSP code of the page, parses it to create the servlet code. For example, in Tomcat you can find servlet classes in the directory TOMCAT / work / Catalina / localhost / WEBAPP / org / apache / jsp . If the JSP page is called home.jsp, then the servlet created will usually be named  home_jsp and the file name is  home_jsp.java .
    1. Compilation – The JSP container compiles the source code for the jsp class and creates a class during this phase.
    1. Class Loading – the container loads the classes into memory during this phase.
    1. Instantiation – the introduction of constructors without parameters of the created classes for initialization in the memory of classes.
    1. Initialization — The container invokes the init method of the JSP class object and initializes the servlet configuration with the init parameters specified in the deployment descriptor ( web.xml ). After this phase, the JSP is able to process client requests. Usually, these phases occur after the first client request (ie, lazy loading), but you can configure JSP loading and initialization at the start of the application, similar to servlets.
    1. Request Processing is a long life cycle of processing client requests by a JSP page. Processing is multi-threaded and similar to servlets — for each request, a new thread is created, ServletRequest and ServletResponse objects are created, and the service of JSP methods is implemented.
  1. Destroy is the last phase of the JSP life cycle in which the JSP class is removed from memory. This usually happens when you turn off the server or andeeply application.

3. Tell us about the jsp life cycle methods.

JSP lifecycle methods:

    • jspInit () – the method is declared in the JSP page and implemented using container implementations. This method is called once in the JSP lifecycle in order to initialize the configuration parameters specified in the deployment descriptor. You can override this method by defining the JSP scripting element and specifying the necessary parameters for initialization.
    • _jspService () – this JSP method is implemented by the JSP container for each client request by passing the request and response object. Note that the method name begins with an underscore and differs from other life cycle methods in that it cannot be overridden. All JSP code goes through this method and is overridden by default. This method is defined in the HttpJspPage interface.
  • jspDestroy () – the method is invoked by the JSP container to remove an object from memory (in the last phase of the JSP life cycle, Destroy). The method is called only once and we can override it to clean up any resources that were created in the JSP init method.

4. What JSP lifecycle methods can be overridden?

We can override the jspInit () and jspDestroy () methods by using JSP scripts. The jspInit () method is   redefined to create shared resources that we would like to use in the JSP maintenance method, and the jspDestroy () method is redefined to free up shared resources in the destruction phase.

5. How can I prevent direct access to a JSP page from a browser?

The WEB-INF directory does not have direct access from the web application. Therefore, we can put JSP pages inside this folder and thus deny access to the page from the browser. However, in this case, you need to configure a deployment descriptor like servlets. A simple configuration of the web.xml descriptor is shown below.

1

2

3

4

5

6

7

8

9

10

11

12

13

<servlet>

 <servlet-name>Test</servlet-name>

 <jsp-file>/WEB-INF/test.jsp</jsp-file>

 <init-param>

   <param-name>test</param-name>

   <param-value>Test Value</param-value>

 </init-param>

</servlet>

   

<servlet-mapping>

 <servlet-name>Test</servlet-name>

 <url-pattern>/Test.do</url-pattern>

</servlet-mapping>

6. How to comment out jsp code?

JSP provides two ways to comment out the code:

    • HTML comments – <- HTML Comment ->  . Such comments will be visible to the client when viewing the page code.
  • JSP comments – <% – JSP Comment -> . Such comments are created in the created servlet and are not sent to the client. For any comments on the code or debug information, you must use this type of comments.

7. Explain Scriptlet, Expression and Declaration in JSP.

Scriptlet, Expression and Declaration are script elements inside JSP pages that can execute Java code. Scriptlets are defined by the <% ..%> tag. Any code inside these tags will be passed to the _jspService () method.

1

2

3

4

<%

Date d = new Date();

System.out.println(“Current Date=”+d);

%>

It is often necessary to display dynamic information using the out.print () method . To do this, there is an expression language (expression), which is written as <% = ..%> . For example, the expression <% out.print (“I love javastudy.ru”); %> can be rewritten using the JSP expression <% = “I love javastudy.ru”%> . Note that everything inside the <% = ..%> tags will be passed to the out.print () method. Also note that scriptlets can contain several java expressions separated by a semicolon, while expressions should not end in a semicolon.

JSP Declaration is used to declare the servlet class methods and variables. Declaration are recorded using the <%! ..%> , for example –  <%! public static int count = 0; %> .

8. What are the implicit, internal objects and methods on the jsp page?

JSP implicit objects are created by the container when converting a JSP page into a servlet code to help developers. These objects can be used directly in scriptlets to transfer information to the service methods, however, we cannot use implicit objects in the JSP Declaration, since such code will go to class level.

There are 9 types of implicit objects that can be used directly on a JSP page. Seven of them are declared as local variables at the beginning of the _jspService () method, and the remaining two can be used as arguments to the _jspService () method .

    1. out object
    1. request Object
    1. response Object
    1. config Object
    1. application object
    1. session object
    1. pageContext Object
    1. page object
  1. exception Object
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

<%@ page language=”java” contentType=”text/html; charset=US-ASCII”

   pageEncoding=”US-ASCII”%>

<%@ page import=”java.util.Date” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “https://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=US-ASCII”>

<title>Index JSP Page</title>

</head>

<body>

<%– out object example –%>

<h4>Hi There</h4>

<strong>Current Time is</strong>: <% out.print(new Date()); %><br><br>

<%– request object example –%>

<strong>Request User-Agent</strong>: <%=request.getHeader(“User-Agent”) %><br><br>

<%– response object example –%>

<%response.addCookie(new Cookie(“Test”,”Value”)); %>

<%– config object example –%>

<strong>User init param value</strong>:<%=config.getInitParameter(“User”) %><br><br>

<%– application object example –%>

<strong>User context param value</strong>:<%=application.getInitParameter(“User”) %><br><br>

<%– session object example –%>

<strong>User Session ID</strong>:<%=session.getId() %><br><br>

<%– pageContext object example –%>

<% pageContext.setAttribute(“Test”, “Test Value”); %>

<strong>PageContext attribute</strong>: {Name=”Test”,Value=”<%=pageContext.getAttribute(“Test”) %>”}<br><br>

<%– page object example –%>

<strong>Generated Servlet Name</strong>:<%=page.getClass().getName() %>

</body>

</html>

9. Why are implicit objects not available in a regular JSP page?

The implicit JSP exception object is not available in regular JSP pages and is used on JSP error pages only to catch the exception thrown by the JSP page and then provide any useful information to the client.

Java Server Pages Interview Questions And Answers

10. What do you know about PageContext and what are the advantages of using it?

The implicit JSP object pageContext is an instance of the implementation of the abstract javax.servlet.jsp.PageContext class  . We can use the pageContext object to get and set attributes with different scopes and to forward requests to another resource. This object also has a link to another implicit object. This is the only object that is represented in JSP implicit objects and JSP EL implicit objects.

11. How to configure init parameters for JSP?

We can set initialization parameters for a JSP in the same way as servlets in a web.xml file. We need to configure the init JSP parameters with servlet and servlet-mapping elements. The only difference is the location of the JSP page.

12. Why is it not recommended to use script elements in jsp?

JSP pages are mainly used for displaying the view, and all business logic and models must be implemented in servlets or classes of models. We must pass parameters to the JSP page through attributes and then use them to create an HTML response on the JSP page. Most JSPs contain HTML code and, in order to help designers understand the code of a JSP page and develop them, provide action, JSP EL, JSP Standart Tag Library elements. These elements must be used instead of scriptlets to create a bridge between JSP HTML and JSP java parts.

13. Can we define a class inside a JSP page?

You can define a class inside a JSP page, but this is considered bad practice. It can be done like this.

1

2

3

4

5

6

7

8

<%!

private static class NestedClass { //static is better because Servlet is multi-threaded

 private final int num = 0;

 public int getNum() {

   return num;

 }

}

%>

or so:

1

2

3

4

5

<%      

   class Person {

       //this will go inside method body, so can’t be public

   }

%>

14. What are the ways to insert java code into jsp page?

Expression , scriptlet , declaration :

JSP Expression <% = Expression%> <% =% expression> XML equivalent:

<jsp: expression> expression </ jsp: expression>.

Predefined variables: request, response, out, session, application, config, and pageContext (also available in scriptlets).

JSP Scriptlet  <% code%> The code is added to the service method. XML equivalent:

<jsp: scriptlet> code </ jsp: scriptlet>.

JSP ad <%! code%> The code is added to the body of the servlet class outside the service method. XML equivalent:

<jsp: declaration> code </ jsp: declaration>.

Directive :

<% @ page att = “value” %> Directives for the servlet engine with basic settings information. XML equivalent:

<jsp: directive.page att = “val” \>. Valid attributes (default values ​​are bold):

import = “packet.class”

contentType = “MIME-Type”

isThreadSafe = ” true | false

” session = ” true | false”

buffer = “sizekb | none”

autoflush = ” true | false ”

extends =“ package.class ”

info =“ message ”

errorPage =“ url ”

isErrorPage =“ true | false

language =” java “

<% @ includefile = “url” %> A file on the local system that is included

when translating a JSP to a servlet.

XML equivalent:

<jsp: directive.include file = “url” \>.

URL must be relative. To include the file during the request process and not during the translation, use the jsp: include action.

Comment :

<% –comment -%> Comment; ignored when translating a JSP page to a servlet. If you want the comment to be preserved in the final HTML, use the usual HTML syntax to describe comments: <- comment ->.

Actions :

<jsp: includepage = “relative URL” flush = “true” /> Includes file when requesting a page. If you want the file to be connected during the page translation process, use the page directive along with the include attribute. Attention: some servers require that the included files be in HTML or JSP format, depending on the server settings (usually this restriction is based on specifying file extensions).
<jsp: useBeanatt = value * /> or

<jsp: useBean att = value *>

</ jsp: useBean>

Find or create Java Bean. Possible attributes:

id = “name”

scope = “page | request | session | application”

class = “package.class”

type = “package.class”

beanName = “package.class”

<jsp: setProperty att = value * /> Sets the bean properties, either explicitly, or by pointing to the corresponding parameter value passed in at the request. Valid attributes:

name = “BeanName”

property = “PropertyName | *”

param = “ParameterName”

value = “Value”

<jsp: getPropertyname = “Name of Property” value = “value”/> Getting and outputting bean properties.
<jsp: forwardpage = “rel.URL ” /> Forwards the request to another page.
<jsp: pluginattribute = “value” *> .. Generates OBJECT or EMBED tags, depending on the type of browser that the applet will be running using the Java Plugin.

15. How can I prevent the use of scripts and java code on the jsp page?

You can disable the use of scripts inside the deployment descriptor. For example, using the pattern from the example below, you can disable the execution of scripts for all JSP pages. Accordingly, to disable scripts of a specific page, you must specify its name.

1

2

3

4

5

6

<jsp-config>

   <jsp-property-group>

       <url-pattern>*.jsp</url-pattern>

       <scripting-invalid>true</scripting-invalid>

   </jsp-property-group>

</jsp-config>

16. What do you know about jsp tags? Explain how you understand the Action tag and JSP Action Elements.

JSP elements or action tags provide useful functionality for working with Java Bean, embedding resources, forwarding a query, and creating dynamic XML elements. The jsp action elements always start with the jsp: entry and we can use them right inside the JSP page without the need to connect libraries or other settings.

The most commonly used action elements are: jsp: useBean , jsp: getProperty , jsp: setProperty , jsp: include , jsp: forward .

17. What is the difference between include and jsp directive: include action?

The difference between the include and jsp JSP directives include action is that for the include directive, content for another resource will be added to the created servlet during the JSP translation phase (Translation phase), while jsp: include action works in runtime.

Another difference in JSP include action is that we can pass parameters to the attachment using the jsp: params command , while the jsp includedirective does not have the ability to pass parameters.

Use the JSP include directive for static resources like header, footer, image file for better performance. If we need dynamics, passing parameters for processing, then we need to use the jsp tag: include action.

18. What do you know about jsp expression language (JSP Expression Language – EL)?

In most cases, we use JSP for viewing purposes, and all business logic is present in the servlet or model classes. After receiving the client’s request, it is processed in the servlet, and then we add attributes to the request / session / context scope, which must be extracted in the JSP code. The request response , headers , cookies, and init parameters are also used to create response views .

We can use scriptlets in JSP expressions to get attributes and parameters in JSP with Java code and use it for views. The problem is that web designers usually do not know java code, which is why JSP 2.0 introduces an expression language (EL) through which we can get attributes and parameters using HTML tags.

The syntax expression language looks like  $ {name} , and we can use EL implicit objects and expression language operators to extract attributes from different scopes and use them in the JSP page.

19. What are the implicit, internal EL JSP objects and their differences from jsp objects?

The JSP expression language provides many implicit objects that can be used to get attributes in various scopes and parameter values. It is important to note that they are different from implicit JSP objects and contain attributes in a given scope. The most commonly used implicit object in the JSP EL and the JSP page is the pageContext object. Below is a table of implicit EL JSP objects.

JSP EL Implicit Objects Type Description
pageScope Map Attribute map for page scope.
requestScope Map Used to get the attributes in the request scope.
sessionScope Map Used to get attributes from the session scope.
applicationScope Map Used to get attributes from the application scope.
param Map Used to get the value of the request parameter, returns one value.
paramValues Map Used to get the values ​​of query parameters in an array. Convenient for query parameters that contain multiple values.
header Map Used to get information about the request header.
headerValues Map Used to get header values ​​in an array.
cookie Map Used to get cookie value in JSP
initParam Map Used to get context init parameters. We cannot use them for servlet initialization parameters (servlet init params).
pageContext pageContext Same as the JSP implicit pageContext object. Used to get request, session references, etc. For example, getting the name request HTTP Method.

Interview Questions on JSP

20. How to find out the name of the http method using JSP EL?

Like this:  $ {pageContext.request.method} .

21. What is JSTL (Jsp Standard tag library)?

JSP Standard Library (JavaServer Pages Standard Tag Library, JSTL) is an extension of the JSP specification that adds a JSP tag library for common needs, such as parsing XML data, conditional processing, creating loops, and supporting internationalization. JSTL is the end result of JSR 52 developed as part of the Java community process.

JSTL is an alternative to this type of logic embedded in JSP as scriptlets, that is, direct insertion of Java code. Using a standardized set of tags is preferable because the resulting code is easier to maintain and easier to separate business logic from the display logic. To use JSTL tags, you must connect the library and specify a namespace on the pages.

1

2

3

4

5

6

7

8

9

10

<dependency>

   <groupId>jstl</groupId>

   <artifactId>jstl</artifactId>

   <version>1.2</version>

</dependency>

<dependency>

   <groupId>taglibs</groupId>

   <artifactId>standard</artifactId>

   <version>1.1.2</version>

</dependency>

To include the namespace of the main JSTL tags, you need to specify the code on the JSP page:

1

2

3

4

5

<%@ taglib uri=”https://java.sun.com/jsp/jstl/core” prefix=”c” %>

<%@ taglib uri=”https://java.sun.com/jsp/jstl/fmt” prefix=”fmt” %>

<%@ taglib uri=”https://java.sun.com/jsp/jstl/sql” prefix=”sql” %>

<%@ taglib uri=”https://java.sun.com/jsp/jstl/xml” prefix=”x” %>

<%@ taglib uri=”https://java.sun.com/jsp/jstl/functions” prefix=”fn” %>

22. Which categories can be divided JSTL tags, give examples.

JSTL tags are divided into five categories according to their functionality:

    1. Core Tags – Core tags provide opportunities for iteration, exception handling, url, forward and redirect response, etc.
    1. Formatting and Localization Tags – provide options for formatting Numbers, Dates, and support for i18n localization and resource bundles.
    1. SQL Tags – JSTL SQL Tags support for working with databases like MySQL, Oracle, etc.
    1. XML Tags – used to work with XML documents. For example, for parsing XML, transforming XML data and executing XPath expressions.
  1. JSTL Functions Tags – provides a set of functions that allow you to perform various operations with strings, etc. For example, by concatenation or splitting strings.

23. What do you know about writing custom jsp tags?

JSP allows you to create your own tags with the necessary functionality. We can add a tag library to a JSP page using the namespace specification. To create your tag, we can use the following components:

    • JSP Custom Tag Handler
    • Creating a Tag Library Descriptor (TLD) File
  • Deployment Descriptor configuration for TLD

24. Give an example of using your own tags.

For example, we need to format a very long number in any style. To do this, you can use your own tag like:

1 <mytags:formatNumber number=”123456.789″ format=”#,###.00″/>

Using the input parameters, the number should be converted on the JSP page in this form 123,456.79 according to the pattern. Since JSTL does not provide this functionality, we will have to create our own tag to get the desired result.

Advanced JSP Interview Questions And Answers

25. Why is it not necessary to configure standard JSP tags in web.xml?

We do not need to configure standard JSP tags in web.xml, because TLD files are already inside the META-INF directory in JSTL jar files. When a container loads a web application and finds TLD files in the META-INF directory in a JAR file, it automatically configures them for direct use on JSP pages. It remains only to set the namespace on the jsp page.

26. How can I handle jsp page errors?

To handle exceptions thrown on the jsp page, you just need to set the error page. To create a JSP error page, we must set the page directive attribute isErrorPage to true. Then we will access the implicit exception objects in the JSP and will be able to pass our own error messages to the client (usually more informative).

Setting up a deployment descriptor looks like this.

1

2

3

4

5

6

7

8

9

<error-page>

<error-code>404</error-code>

<location>/error.jsp</location>

</error-page>

 

<error-page>

<exception-type>java.lang.Throwable</exception-type>

<location>/error.jsp</location>

</error-page>

27. How does error handling occur with jstl?

You can catch exceptions and process them in the class utility methods using JSTL Core Tags c: catch and c: if . The c: catch tag catches an exception and wraps it in a variable of exception, which we can handle in the c: if tag .

1

2

3

4

5

6

7

8

<c:catch var =”exception”>

  <% int x = 5/0;%>

</c:catch>

 

<c:if test = “${exception ne null}”>

  <p>Exception is : ${exception} <br />

  Exception Message: ${exception.message}</p>

</c:if>

Notice that the EL JSP expression language in the c: if tag is used .

28. How to make a “new line in HTML” in JSP?

To transfer a line, you can use the c: out tag and the escapeXml attribute to disable processing of HTML elements and the browser will receive the following code as a string (and will process the <br> element as required).

1 <c:out value=”<br> creates a new line in HTML” escapeXml=”true”></c:out>

29. Give a sample JSP configuration in the deployment descriptor.

The jsp-config element is used to configure various parameters of jsp pages.

    • management of scriptlet elements on the page,
    • controlling the execution of expressions in a language
    • URL pattern definition for encoding,
    • determining the size of the buffer that is used for objects on the page
  • Identification of resource groups corresponding to a URL pattern to be processed as an XML document.
1

2

3

4

5

6

jsp-config>

       <taglib>

           <taglib-uri>https://journaldev.com/jsp/tlds/mytags</taglib-uri>

           <taglib-location>/WEB-INF/numberformatter.tld</taglib-location>

       </taglib>

</jsp-config>

JSP Interview Questions And Answers For Experienced

30. How to deactivate EL usage on JSP?

There are two ways to ignore the execution of an expression language on a page:

    • use the directive  <% @ page isELIgnored = “true”%> ,
  • configure web.xml (better suited to be disabled on EL on many pages)
1

2

3

4

5

6

<jsp-config>

   <jsp-property-group>

       <url-pattern>*.jsp</url-pattern>

       <el-ignored>true</el-ignored>

   </jsp-property-group>

</jsp-config>

31. When does a container initialize multiple JSP / Servlet objects?

If there are several servlets and servlet-mapping elements in the deployment descriptor for one servlet or JSP page, then the container initializes an object for each element and each of these objects has its own ServletConfig object and initialization parameters.

For example, if we use one JSP page in web.xml as shown below.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

<servlet>

 <servlet-name>Test</servlet-name>

 <jsp-file>/WEB-INF/test.jsp</jsp-file>

 <init-param>

   <param-name>test</param-name>

   <param-value>Test Value</param-value>

 </init-param>

</servlet>

   

<servlet-mapping>

 <servlet-name>Test</servlet-name>

 <url-pattern>/Test.do</url-pattern>

</servlet-mapping>

   

<servlet>

 <servlet-name>Test1</servlet-name>

 <jsp-file>/WEB-INF/test.jsp</jsp-file>

</servlet>

   

<servlet-mapping>

 <servlet-name>Test1</servlet-name>

 <url-pattern>/Test1.do</url-pattern>

</servlet-mapping>

Then when accessing a single JSP page with two URI patterns, there will be two sets of initialization parameters.

32. Can i use javascript on jsp page?

Yes it is possible. Despite the fact that JSP is a server technology, it still creates an HTML page, to which you can also add javascript code and css styles.

33. Is the session object always created on the jsp page, is it possible to disable its creation?

By default, the jsp page creates a session, but sometimes it is not needed. We can use page directive with the session attribute to specify not to create a new session by default. To disable session creation, use the code shown below.

1 <%@ page session =”false” %>

34. What is the difference between a JspWriter and a Servlet PrintWriter?

The PrintWriter is the response object for recording the content in the response. JspWriter uses the PrintWriter object imperceptibly to the user and provides buffering support. When the buffer is full or empty, JspWriter uses the PrintWriter object to write the content (content) to the response.

35. How can I extend the functionality of jsp?

We can extend JSP technology by creating our own tags to avoid using scriptlets and java code on JSP pages.

36. Best Practices in JSP.

The following tips are good practices for working with JSP technology:

    • Avoid using scriptlet elements on the page. If the action, JSTL, JSP EL elements do not meet the needs, then write your own tag.
    • Use different kinds of comments as intended. JSP comments are needed for code level and debugging, since they will not be shown to the client.
    • Avoid writing business logic inside a JSP page. Pages should only be used to create customer responses.
    • Disable session creation on the page when it is not required. This will increase productivity.
    • Use the taglib, page directives at the beginning of the JSP page to increase the readability of the code.
    • Properly use the include and jsp directive: include action. The first is used for static resources, and the jsp element: include action for dynamic runtime resources.
    • Handle exceptions using error pages. This will help to avoid processing on the side of the service exception method and can improve performance.
    • When using CSS and JavaScript, separate them into different files and include them at the top of the page.
  • In most cases, JSTL should suffice for all needs. If this is not the case, then first look at the logic of your application, as well as try transferring code execution to the servlet, and then using the attribute setting use the result on the JSP page.

Must Read Java Interview Questions Books 2020

RELATED INTERVIEW QUESTIONS

  1. JPA Interview Questions
  2. Spring Framework Interview Questions
  3. Spring Boot Interview Questions
  4. GIT Interview Questions And Answers
  5. Network Security Interview Questions
  6. CheckPoint Interview Questions
  7. Page Object Model Interview Questions
  8. Apache Pig Interview Questions
  9. Python Interview Questions And Answers
  10. Peoplesoft Integration Broker Interview Questions
  11. PeopleSoft Application Engine Interview Questions
  12. RSA enVision Interview Questions
  13. RSA SecurID Interview Questions
  14. Archer GRC Interview Questions
  15. RSA Archer Interview Questions
  16. Blockchain Interview Questions
  17. Commvault Interview Questions
  18. Peoplesoft Admin Interview Questions
  19. ZooKeeper Interview Questions
  20. Apache Kafka Interview Questions
  21. Couchbase Interview Questions
  22. IBM Bluemix Interview Questions
  23. Cloud Foundry Interview Questions
  24. Maven Interview Questions
  25. VirtualBox Interview Questions
  26. Laravel Interview Questions
  27. Logstash Interview Questions
  28. Elasticsearch Interview Questions
  29. Kibana Interview Questions
  30. JBehave Interview Questions
  31. Openshift Interview Questions
  32. Kubernetes Interview Questions

Leave a Comment