Pr.Pg Next Pg

JSP Interview Questions and Answers Part 10

 

91.What is a scriptlet?

  • A scriptlet contains Java code that is executed every time a JSP is invoked. When a JSP is translated to a servlet, the scriptlet code goes into the service() method.

  • Hence, methods and variables written in scriptlets are local to the service() method.

  • A scriptlet is written between the <% and %> tags and is executed by the container at request processing time.

 

92.What are JSP declarations?

  • As the name implies, JSP declarations are used to declare class variables and methods in a JSP page. They are initialized when the class is initialized.

  • Anything defined in a declaration is available for the whole JSP page.

  • A declaration block is enclosed between the <%! and %> tags.

  • A declaration is not included in the service() method when a JSP is translated to a servlet.

 

93.What is a JSP expression?

  • A JSP expression is used to write an output without using the out.print statement.

  • It can be said as a shorthand representation for scriptlets.

  • An expression is written between the <%= and %> tags.

  • It is not required to end the expression with a semicolon, as it implicitly adds a semicolon to all the expressions within the expression tags.

 

94.What is the _jspService() method?

  • The _jspService() method of the javax.servlet.jsp.HttpJspPage interface is invoked every time a new request comes to a JSP page.

  • This method takes the HttpServletRequest and HttpServletResponse objects as its arguments.

  • A page author cannot override this method, as its implementation is provided by the container.

 

95.How many JSP scripting elements are there and what are they?

  • There are three scripting language elements: declarations, scriptlets, expressions

 

96.In the Servlet 2.4 specification SingleThreadModel has been deprecated, why?

  • Because it is not practical to have such model.

  • Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level.

 

 

97.Is JSP technology extensible?

  • YES.

  • JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

 

98.How can a servlet refresh automatically if some new data has entered the database?

  • You can use a client-side Refresh or Server Push.

 

99.The code in a finally clause will never fail to execute, right?

  • Using System.exit(1); in try block will not allow finally code to execute.

 

100.How many messaging models do JMS provide for and what are they?

  • JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing.


Pr.Pg border                                              Next Pg