Pr.Pg Next Pg

JSP Interview Questions and Answers Part 7


61.How to Retrieve Warnings?

  • SQLWarning objects are a subclass of SQLException that deal with database access warnings.

  • Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned.

  • A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object.

  • Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object

SQLWarning warning = stmt.getWarnings();
if (warning != null)
while (warning != null)
System.out.println(\"Message: \" + warning.getMessage());
System.out.println(\"SQLState: \" + warning.getSQLState());
System.out.print(\"Vendor error code: \");
warning = warning.getNextWarning();


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

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


63In 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.


64.Is JSP technology extensible?

  • YES.

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


65.Can we use the constructor, instead of init(), to initialize servlet?

  • Yes , of course you can use the constructor instead of init().

  • There’s nothing to stop you. But you shouldn’t.

  • The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig.

  • That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.


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

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


67.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.


68.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.


69.What are the advantages of JSP over Servlet?

  • JSP is a serverside technology to make content generation a simple appear.T

  • he advantage of JSP is that they are document-centric.

  • Servlets, on the other hand, look and act like programs.

  • A Java Server Page can contain Java program fragments that instantiate and execute Java classes, but these occur inside an HTML template file and are primarily used to generate dynamic content. Some of the JSP functionality can be achieved on the client, using JavaScript.

  • The power of JSP is that it is server-based and provides a framework for Web application development.


70.What is the life-cycle of JSP?

  • When a request is mapped to a JSP page for the first time, it translates the JSP page into a servlet class and compiles the class.

  • It is this servlet that services the client requests.
    A JSP page has seven phases in its lifecycle, as listed below in the sequence of occurrence:

  • Translation

  • Compilation

  • Loading the class

  • Instantiating the class

  • jspInit() invocation

  • _jspService() invocation

  • jspDestroy() invocation

Pr.Pg border                                              Next Pg