• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

JSP Interview Questions Answers

Question - 21 : - How to Retrieve  Warnings?

Answer - 21 : - 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 - 22 : - Can a JSP page process HTML FORM data?

Answer - 22 : - Yes. However, unlike Servlet, you are not required to implement HTTP-protocol specific methods like doGet() or doPost() within your JSP page. You can obtain the data for the FORM input elements via the request implicit object within a scriptlet or expression as.

Question - 23 : - Why does JComponent have add() and remove() methods but Component does not?

Answer - 23 : - because JComponent is a subclass of Container, and can contain other components and jcomponents. How can I implement a thread-safe JSP page? - You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

Question - 24 : - How do you connect to the database from JSP?

Answer - 24 : - A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets. Further then you can use the resultset object "res" to read data in the following way.

Question - 25 : - How can I implement a thread-safe JSP page?

Answer - 25 : - You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

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

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

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

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

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

Answer - 28 : - 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 - 29 : - What JSP lifecycle methods can I override?

Answer - 29 : - You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page. It is good programming practice to free any allocated resources within jspDestroy(). The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are typically declared as JSP declarations:

Question - 30 : - Can we override the jspInit(), _jspService() and jspDestroy() methods?

Answer - 30 : - We can override jspinit() and jspDestroy() methods but not _jspService().

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners