• +91 9723535972
  • info@interviewmaterial.com

JSP Interview Questions and Answers

JSP Interview Questions and Answers

Question - 61 : - How can my application get to know when a HttpSession is removed?

Answer - 61 : - Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession.

Question - 62 : - What Class.forName  will do while loading drivers?

Answer - 62 : - It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.

Question - 63 : - How many JSP scripting elements are there and what are they?

Answer - 63 : - There are three scripting language elements: declarations, scriptlets, expressions.

Question - 64 : - How to Retrieve  Warnings?

Answer - 64 : - 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: \"); System.out.println(warning.getErrorCode()); warning = warning.getNextWarning(); } }

Question - 65 : - In the Servlet 2.4 specification  SingleThreadModel has been deprecated, why?

Answer - 65 : - 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.

Question - 66 : - Can we use the constructor,  instead of init(), to initialize servlet?

Answer - 66 : - 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.

Question - 67 : - How can a servlet refresh automatically if  some new data has entered the database?

Answer - 67 : - You can use a client-side Refresh or Server Push.

Question - 68 : - The code in a finally clause will never fail to execute, right?

Answer - 68 : - Using System.exit(1); in try block will not allow finally code to execute.

Question - 69 : -
Explain the JSP for loop.

Answer - 69 : -

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
{
          //block of statements
}

Question - 70 : - Explain the JSP while loop.

Answer - 70 : -

The JSP While loop is used to iterate the elements where it has one parameter of the condition.

Syntax of While loop:

While(i
{
     //Block of statements
}


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners