• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

JSP Interview Questions Answers

Question - 51 : - Can you override jspInit() method? If yes, In which cases?

Answer - 51 : - ye, we can. We do it usually when we need to initialize any members which are to be available for a servlet/JSP throughout its lifetime.

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

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

Question - 53 : - How is JSP include directive different from JSP include action?

Answer - 53 : - When a JSP include directive is used, the included file's code is added into the added JSP page at page translation time, this happens before the JSP page is translated into a servlet. While if any page is included using action tag, the page's output is returned back to the added page. This happens at runtime.

Question - 54 : - How do I perform browser redirection from a JSP page?

Answer - 54 : - You can use the response implicit object to redirect the browser to a different resource, as: response.sendRedirect("http://exammaterial.com"); You can also physically alter the Location HTTP header attribute, as shown below: You can also use the: Also note that you can only use this before any output has been sent to the client. I beleve this is the case with the response.sendRedirect() method as well. If you want to pass any paramateres then you can pass using >

Question - 55 : - Is there a way to reference the "this" variable within a JSP page?

Answer - 55 : - Yes, there is. Under JSP 1.0, the page implicit object is equivalent to "this", and returns a reference to the Servlet generated by the JSP page.

Question - 56 : - What is JSP technology?

Answer - 56 : - Java Server Page is a standard Java extension that is defined on top of the servlet Extensions. The goal of JSP is the simplified creation and management of dynamic Web pages. JSPs are secure, platform-independent, and best of all, make use of Java as a server-side scripting language.

Question - 57 : - Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?

Answer - 57 : - You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable. This has to be consider as "passed-by-value", that means that it's read-only in the EJB. If anything is altered from inside the EJB, it won't be reflected back to the HttpSession of the Servlet Container.The "pass-byreference" can be used between EJBs Remote Interfaces, as they are remote references. While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be "bad practice" in terms of object oriented design. This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession). Create a higher-level of abstraction for your ejb's api. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your ejb needs to support a non-http-based client. This higher level of abstraction will be flexible enough to support it.

Question - 58 : - How do I prevent the output of my JSP or Servlet pages from being cached by the browser?

Answer - 58 : - You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser. You need both the statements to take care of some of the older browser versions.

Question - 59 : - How to Retrieve Warnings?

Answer - 59 : - 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 - 60 : - How many JSP scripting elements are there and what are they?

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

Computer Contributors

Rajeev Katiyar
Yes Baroda

Share your email for latest updates


Our partners