Thursday, October 29, 2026
HomeArtificial Intelligence45 Prime JSP Interview Questions

45 Prime JSP Interview Questions

[ad_1]

JSP Interview Questions

Within the early days, there have been numerous instruments to develop dynamic internet content material equivalent to Frequent Gateway Interface (CGI), mod_perl from Apache, ISAPI from Microsoft. All of them tried to generate internet pages by embedding HTML directories right into a programming language. Due to this, the creation of dynamic internet pages is pushed into the realm of programmers. Java Server Pages, nevertheless, modifications all that.

JSP is a text-based program, which incorporates each HTML and Java code. JSP allows you to embed specialised code, also called a script, into HTML pages. By default, Java is used as a scripting language in JSP.  However the JSP specification can embody different scripting languages as effectively, equivalent to JavaScript, Perl, and VBScript. Even with all the newest know-how accessible, many corporations use Java as a Base language. These corporations additionally use JSP to develop dynamic internet pages and internet purposes.

Therefore, it’s anticipated that the best candidate for Java should find out about JSP. Having identified the significance of JSP, let’s start with the highest JSP Interview Questions which can be requested continuously in interviews.

  1. JSP Interview Questions for Freshers
  2. JSP Interview Questions for Skilled
  3. Conclusion

JSP Interview Questions for Freshers

1. What’s JSP and why do we’d like it?

JSP stands for Java Server Pages. JSP is server-side know-how to create dynamic internet pages. JSP is an extension of servlet know-how to assist builders create dynamic internet pages with HTML-like syntax.

JSP is much less error-prone and simple to keep up than servlet. Many of the parts on an internet web page are static, so the JSP web page is extra appropriate for the net web page. There are JSP scripting parts that permit one to jot down java code in JSP pages. We are able to additionally use JSP motion tags, JSTL tags, or customized tags to attain the identical functionalities.

Yet one more good thing about JSP is that many of the containers help the new improvement of JSP pages. We are able to make the required modifications in JSP and exchange the outdated JSP web page with the up to date JSP web page within the improvement listing, and the container will load the brand new JSP web page. There isn’t a must compile venture code or restart the server, but when the modifications are made in servlet code modifications, we have to construct the whole venture once more and deploy it. These days, virtually all containers present scorching deployment help for the applying, however it’s extra work than JSP pages.

2. What are JSP motion tags?

JSP motion tags are HTML-like tags that present helpful functionalities equivalent to JSP:useBean is to work with Java Bean, JSP: embody a useful resource, JSP: ahead is to ahead the request or response, JSP:setProperty is to set a property worth in bean object. JSP motion tag all the time begins with JSP: and we are able to use them within the JSP web page straight with none want for configuration modifications or importing any library.

3. Clarify the JSP life cycle

Any JSP file goes by way of 7 levels and that’s referred to as life cycle phases:

  1. Translation: JSP first goes to the Container, the place it’s parsed to generate servlet code. If the servlet class is older than JSP, then the Container parses it once more. Else it’s skipped.
  2. Compilation: After translation, Container compiles JSP supply code to create a category file.
  3. Loading: The Container hundreds the compiled class into reminiscence.
  4. Instantiation: Container invokes constructor that has zero arguments to instantiate it. 
  5. Initialization: Container Calls the jspInit() technique to initialize the servlet occasion. After this, JSP can deal with the shopper request.
  6. Request Processing: After initialization, new threads are created with the _jspService() technique. This technique may have request and response object parameters. Every thread will course of shopper requests the identical because the servlet.
  7. Destroy: After the processing is over, the JSP class is unloaded from reminiscence utilizing the jspDestroy() technique.

4. What’s a JSP container?

A JSP container is an entity that’s used to translate, execute, and course of JSP pages and ship requests to them. The precise make-up of a JSP container depends upon the implementation, however it should include a servlet or assortment of servlets. Therefore, the JSP container is executed by a servlet container.

5. Are you able to override any of the life cycle strategies talked about above?

jspInit() and jspDestory() strategies might be overridden if required. jspInit()  might be overridden to create widespread sources that can be utilized in service strategies equivalent to database connections in the identical method jspDestroy() is used to launch widespread sources which can be created utilizing jspInit().

6. What are the context initialization parameters?

The parameters used for initialization for the entire utility. They don’t seem to be particular to any servlet or JSP. These parameters are laid out in internet.xml utilizing <context-param> tag.

7. What are some advantages of utilizing JSP?

  • JSP gives a easy, but highly effective, option to create dynamic internet pages. 
  • JSP pages are compiled into Java bytecode, which improves efficiency and permits them to run on any Java-enabled internet server. 
  • JSP tags present a handy option to create reusable elements that may be shared amongst a number of pages. 
  • JSP pages might be built-in with Java code, permitting you to create customized elements and extensions. 
  • JSP pages might be simply custom-made and configured to fulfill the wants of your utility.

8. What are the implicit objects in JSP? Are you able to title them?

The objects that don’t require declaration first are generally known as implicit objects. Following are the implicit objects in JSP:

Out, request, response, session, config, exception, web page, pageContext, utility. 

9. What’s the distinction between embody directive and embody motion tag?

Each embody directives and embody motion tags are used so as to add a file into the prevailing JSP. The distinction is in the way in which they embody the file.

  1. Embody directive contains the file throughout translation stage of life cycle whereas, the embody motion contains the file at runtime.
  2. If the included file is modified however not the JSP which is together with it then the modifications is not going to replicate if the embody directive is used. As a result of jsp isn’t modified and meaning it is not going to be translated for the request. For such a station an motion tag must be used.
  3. Syntax distinction: 

Embody directive: <%@ embody file=”file_name” %> and 

embody motion: <jsp:embody web page=”file_name” />.

  1. We are able to use the motion tag with or with out parameters. The identical can’t be carried out within the embody directive.
  2. We are able to use the motion tag with or with out parameters. The identical can’t be carried out within the embody directive.

10. What are Servlets?

Servlets are a Java know-how that allows internet builders to create dynamic content material for internet servers. Servlets are sometimes used to course of or retailer info from a request from a shopper, equivalent to an internet browser, and return a response to the shopper.

11. Is it potential to make use of the exception implicit object in any JSP web page?

No. The exception implicit object is used within the error web page, which defines it with the isErrorPage attribute of the web page directive.

12. Checklist down all of the scope values for the <jsp.useBean> tag

There are 4 scope values for the given tag.

  1. Web page
  2. Request
  3. Session
  4. Software.

13. Checklist down all of the Literals utilized in JSP

  1. Boolean
  2. Integer
  3. Floating Level
  4. String
  5. Null

14. What are JSP Operators?

The JSP Operators are the symbols which can be made to make use of for the manipulation of knowledge. The operators are used for creating, evaluating, and manipulating the info. These operators might be divided into 3 elements: arithmetic, logical, and string operators.

15. What’s the distinction between JSP and Javascript?  

Javascript is a language that’s used to create interactivity on internet pages. JSP is a Java servlet that helps within the improvement of internet pages.

16. Is JSP know-how extensible?

JSP know-how is extensible. It may be prolonged with JavaBeans elements and JavaServer Faces elements.

17. What’s the function of the PageContext implicit object?

JSP PageContext implicit object is an occasion from java.servlet.jsp.PageContext summary class implementation. It’s used to get and set attributes, ahead requests to different sources and maintain references to different implicit objects.

18. How do you utilize JSP within the MVC mannequin?

JSP is often used for presentation within the MVC. It acts as a view. The controller offers with calling the mannequin and the enterprise lessons, which in flip get the info, and this knowledge is then offered to the JSP for rendering to the shopper.

JSP Interview Questions for Skilled

19. How will you keep away from direct entry to any JSP from the shopper browser?

We are able to place the file contained in the WEB-INF listing because the WEB-INF listing can’t be accessed in an internet browser. We may also need to configure file particulars in internet.xml. Following is the syntax to configure such JSP.

<servlet>
<servlet-name>Take a look at</servlet-name>
<jsp-file>WEB-INF/take a look at.jsp</jsp-file>
<init-param>
<param-name>take a look at</param-name>
<param-value>Take a look at Worth</param-value>
</init-param>
</servlet>
   
<servlet-mapping>
<servlet-name>Take a look at</servlet-name>
<url-pattern>/Take a look at.do</url-pattern>
</servlet-mapping>.

20. How will you disable Java code(Scriplet) in JSP

Syntax to disable java code:

<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
</jsp-config>

21. What’s the function of the JSP declaration tag?

Any technique or variable that we wish to use might be declared utilizing the JSP declaration tag.

Syntax:

<%! variable/technique title %>.

22. How will you disable caching on the again button?

Syntax:

<%response.setHeader("Cache-Management","no-store"); response.setHeader("Pragma","no-cache"); 
response.setHeader ("Expires", "0"); %>

23. Point out the sorts of feedback that can be utilized in JSP 

There are two sorts of feedback in JSP:

  1. HTML Feedback: These feedback are seen within the HTML supply code. 

Syntax for HTML remark: <!–Remark–>.

  1. JSP Feedback: These feedback should not seen in HTML supply code. That’s the reason they’re additionally referred to as hidden feedback. For code-level debugging info, these are appropriate choices.

Syntax for JSP remark: <%–Remark–%>.

24. What’s Expression Language (EL) in JSP?

Expression Language (EL) was launched in JSP 2.0 primarily to simplify the accessibility of knowledge saved in java beans. To get attributes or parameters with the assistance of HTML tags. It can be used for arithmetic, relational or logical operations.

Syntax: ${Expression}

Any given expression contained in the bracket will likely be evaluated at runtime.

25. Write syntax for Expression Language to get the HTTP technique title

Syntax: ${pageContext.request.technique}.

26. Point out among the predefined implicit objects in EL

Following are the accessible implicit objects in EL:

  1. pageScope: It’s used to map values from the web page scope.
  2. pageContext: It gives entry to Object requests, session
  3. sessionScope: It’s used to map values from the session scope.
  4. requestScope: It’s used to map values from the request scope. Attributes are set by request implicit object.
  5. param: It’s used to map parameters to a single worth.
  6. applicationScope: It’s used to map values from the applying scope.
  7. header: It’s used to map request header title to the only worth
  8. headerValues: It’s used to map the request header title to the only values
  9. initParam: It’s used to map the Initialization Parameter
  10. paramValues: It’s used to map the request parameter to an array of values
  11. cookie: It’s used to cookie title to the cookie worth

27. Checklist down attributes on web page directives

 Following are the attributes of the Web page Directives

  1. Session: To indicate if any session knowledge is accessible to the web page or not.
  2. Import: It’s declared to point out a listing of packages which can be imported
  3. isELIgnored: It’s used when jsp transforms into servlet to point out whether or not EL expressions are ignored or not.
  4. contentType: To permit the consumer to specify the content-type of the web page.

28. What are Consumer-side and server-side validation?

Validations carried out on the client-side are referred to as client-side validations; equally, validations carried out on the server-side are referred to as server-side validations. Each validations are written in JavaScript. If client-side validations are profitable, then solely knowledge is submitted, whereas on the server-side, all knowledge is submitted, after which the validations are carried out. In such instances, if there may be some error, then the additional community journey is required to resend the shape to the shopper to refill the shape with the proper knowledge.

29. Clarify Object Cloning

Object cloning is used to create an actual copy of the prevailing object. The clone() technique of the Object class is used to create the clone of an present object. As a prerequisite, The category whose object the consumer tries to clone is predicted to implement the java.lang.Cloneable interface.

30. Write an instance of the clone technique

Syntax:

class FullName implements Cloneable{ 
     String Firstname;
     String Lastname; 
     FullName(String Firstname,String Lastname){ 
          this.Firstname=Firstname; 
          this.Lastname=Lastname; 
     } 
    public Object clone()throws CloneNotSupportedException
{ 
          return tremendous.clone(); 
     } 
     public static void essential(String args[])
{ 
          Attempt
{ 
               FullName s1=new FullName("Karan","Dalal"); 
               FullName s2=(FullName)s1.clone(); 
          System.out.println(s1.Firstname+" "+s1.Lastname); 
          System.out.println(s2.Firstname+" "+s2.Lastname); 
          }
          catch(CloneNotSupportedException c)
{
            } 
     } 
}

The above code will print the string “Karan Dalal” twice.

31. Clarify Auto-Flush attributes

When the buffer is stuffed or whether or not an exception needs to be raised to point buffer overflow, The Auto-Flush attribute specifies if a buffered output needs to be flushed robotically or not. To carry out computerized flushing, the attribute is about to true. Whether it is set to false, then an exception will likely be raised.

32. How do you delete session knowledge?

Following are steps to delete session knowledge:

  1. Take away explicit attribute:

Syntax: public void removeAttribute(String title)

  1. Discard the entire session:

Syntax: public void invalidate()

  1. Setting particular person session timeout:

Syntax: public void setMaxInactiveInterval(int interval)

  1. Logout consumer: logout consumer from the net server and invalidate session belonging to the consumer.

33. Write syntax to delete cookies in JSP

Syntax: 

Cookie mycookie = new Cookie("title","worth");
response.addCookie(mycookie);
Cookie killcookie = new Cookie("mycookie","worth");
killcookie . set MaxAge ( 0 );
killcookie . set Path (" / ");
killcookie . addCookie ( killcookie 1 );

34. What’s JSTL?

JSTL stands for JSP Normal Tag Library. It’s a part of Java EE API and is included in most servlet containers. JSTL can use a loop by way of a group. It can be used to flee HTML tags to point out them as textual content in response. Due to this, it’s thought of extra versatile than Expression language. 

35. Checklist down several types of JSTL tags

JSTL tags are categorized into 5 varieties:

  1. Core Tags: These tags are used to help Iteration, conditional logic, catch an exception, URL, ahead, or redirect response.
  2. Formatting and Localization Tags: These tags are used for the formatting of numbers or dates.
  3. SQL Tags: These tags are used to help interplay with relational databases like MySql or Oracle.
  4. XML Tags: These tags are used to work with XML paperwork to carry out features equivalent to Parsing XML or reworking XML knowledge.
  5. JSTL features tag: JSTL tags present some features to carry out widespread operations like string concatenation or cut up.

36. Checklist down JSTL core tags

  1. <c:out> tag: It’s used to show the content material on shopper after escaping XML and HTML markup tags. Primary attributes are default and escapeXML.
  2. <c:set> tag: This tag is used to arrange a variable worth in a specified scope. It units the outcome for a given expression within the given variable.
  3. <c: take away> tag: It’s used to take away an attribute from a specified scope, By default removes it from all scopes.
  4. <c: if> tag: This JSTL core tag is used for testing circumstances. There are two different optionally available attributes for this tag, var, and scope.
  5. <c:select> tag: It’s used as a swap case.
  6. <c:when> tag: It’s like a case assertion in Java.
  7. <c:in any other case> tag: It’s used because the default attribute in switch-case statements.
  8. <c:catch>tag: This tag is utilized in exception dealing with.
  9. <c:import> tag: It is a core JSTL tag. It’s used for importing the content material from one other file or web page to the present JSP web page. Attributes required are var, URL, and scope.
  10. <c:forEach> tag: This tag in JSTL works as for look from java 
  11. <c:forTokens> tag: It’s used for iteration nevertheless it solely works with the delimiter.
  12. <c:param> tag: This JSTL tag is usually used with <c:url> and <c:redirect> tags. It provides parameters and their values to the output of those tags.
  13. <c:url> tag: It’s used for URL formatting or URL encoding. It converts a relative URL into an utility context’s URL.
  14. <c:redirect> tag: It’s used, to redirect the present web page to a different URL, present the relative handle within the URL attribute of this tag and the web page will likely be redirected to the URL.

37. What’s the JSP customized tag and the way are they created?

In JSP, there are a number of predefined tags, however in some instances, these tags is probably not enough. In such a scenario, we are able to create a tag of our personal to fulfill the wants. Such tags are referred to as customized tags.

Following are the steps to create a customized tag:

  1. Create tag handler class: that is the file that can have logic for the customized tag. First, inherit the TagSupport Class after that, override doStartTag() technique. Use JspWriter class in order that we are able to write knowledge for jsp. The PageContext class gives getOut() technique which returns the occasion of the JspWriter class. After this, the TagSupport class gives an occasion of pageContext by default.
  2. Creating Tag Library Descriptor (TLD) File: this file is created contained in the WEB-INF listing. It has info associated to the tag that we wish to create and the tag handler class.
  3. Creating the JSP file: this file ought to specify the trail of the TLD file.it makes use of taglib directive to make use of tags which can be outlined in TLD 

38. What are the variations between the JSP customized tag and java beans?

  1. JSP content material might be manipulated utilizing customized tags. The identical can’t be carried out by java beans.
  2. In customized tags, we are able to simplify advanced operations. The identical can’t be carried out by java beans.
  3. The customized tag requires some quantity of labor to arrange as in comparison with java beans.

39. Checklist down the tags utilized in JSP bean improvement

  1. jsp:useBean
  2. jsp:setProperty
  3. jsp:getProperty

40. What are the strategies used to learn knowledge from JSP kind?

Relying on the scenario following features can be utilized to learn knowledge from JSP:

  1. getParameter(): this technique is used when there’s a single parameter to learn. 
  2. getParameterValues(): This technique is used when there the parameter seems greater than as soon as and returns a number of values.
  3. getParameterNames(): This technique is used to fetch the checklist of all parameters within the present request.
  4. getInputStream(): This technique is used to learn binary knowledge streams coming from the shopper.

41. What would you like between JSP pages and applets to design web-based shopper packages?

Between two JSP pages is preferable as there isn’t a want for plug-ins or safety coverage information. JSP utility programming and JSP design are carried out individually offering a extra modular method. 

42. Are you able to retrieve SQL warnings in JSP?

We are able to retrieve SQL warnings by utilizing SQLWarning objects. It may be reported on a Connection object, a Assertion object together with PreparedStatement and CallableStatement objects.

The syntax for warning on assertion object:

SQLWarning warning = stmt.getWarnings();
String Warning=   warning.getMessage();


43. Write syntax for the servlet to speak with JSP

To speak with JSP, servlet instantiates a bean and initializes it with FORM knowledge posted by a browser. The bean is then positioned into the request, and the decision is then forwarded to the JSP web page.

Contemplate the next servlet to speak the primary title and final title to Bean01.jsp.

Servlet syntax to set knowledge earlier than the request is forwarded.

public void doPost (HttpServletRequest request, HttpServletResponse response){
     strive {
           govi.FormBean f = new govi.FormBean();
           String id = request.getParameter("id");
           f.setName(request.getParameter("title"));
           f.setAddr(request.getParameter("addr"));
           f.setAge(request.getParameter("age"));
           f.setPersonalizationInfo(data);
           request.setAttribute("fBean",f);
           getServletConfig().getServletContext().getRequestDispatcher
           ("/jsp/Bean01.jsp").ahead(request, response);
     }
     catch (Exception ex) {
     }
}

We are able to use the getProperty operate to retrieve forwarded knowledge.

Syntax:

jsp:useBean id="fBean" class="govi.FormBean" scope="request"/ jsp:getProperty title="fBean"
property="title" / jsp:getProperty title="fBean"
property="addr" / jsp:getProperty title="fBean" property="age" / jsp:getProperty title="fBean"
property="personalizationInfo" /
 
 
 
 

44. Write syntax to disable Expression language (EL) on JSP

To disable EL in a single file utilizing the next directive:

<% @ web page isELIgnored = “true”%>.

If we wish to disable EL on a number of information we are able to configure the identical in internet.xml:

<jsp-config>
   <jsp-property-group>
       <url-pattern>*.jsp</url-pattern>
       <el-ignored>true</el-ignored>
   </jsp-property-group>
</jsp-config>

45. Clarify circumstances during which the container initializes a number of JSP objects

If there are a number of servlets and if one servlet or JSP web page has a number of servlet-mapping parts within the deployment descriptor, then the container initializes an object for every factor, and every of those objects has its ServletConfig object and initialization parameters. 

The syntax for one JSP web page utilized in internet.xml file:

<servlet>
<servlet-name>TestServlet</servlet-name> 
     <jsp-file>/WEB-INF/take a look at.jsp</jsp-file>
         <init-param>
             <param-name>take a look at</param-name>
             <param-value>Take a look at Worth</param-value>
         </init-param>
</servlet>
 
<servlet-mapping>
      <servlet-name>Take a look at</servlet-name>
      <url-pattern>/Take a look at.do</url-pattern>
</servlet-mapping>
 
<servlet>
      <servlet-name>Test1</servlet-name>
      <jsp-file>/WEB-INF/take a look at.jsp</jsp-file>
</servlet>
 
<servlet-mapping>
      <servlet-name>Test1</servlet-name>
      <url-pattern>/Test1.do</url-pattern>
</servlet-mapping>.

Summing Up

This brings us to the tip of the weblog on the highest JSP Interview Questions. We hope that you just had been capable of profit from these questions and are actually higher geared up on your upcoming interview course of. To study extra such ideas, take a look at a pool of Free On-line Programs provided by Nice Studying Academy.

One such free course is the Java Programming course at Nice Studying Academy.

java

0

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments