• +91 9971497814
  • info@interviewmaterial.com

JSP Interview Questions Answers

Question 1 : Can a JSP page instantiate a serialized bean?

Answer 1 : No problem! The use Bean action specifies the beanName attribute, which can be used for indicating a serialized bean. For example: A couple of important points to note. Although you would have to name your serialized file "filename.ser", you only indicate "filename" as the value for the beanName attribute. Also, you will have to place your serialized file within the WEB-INFjspbeans directory for it to be located by the JSP engine.

Question 2 : Can a JSP page process HTML FORM data?

Answer 2 : 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 3 : Can I stop JSP execution while in the midst of processing a request?

Answer 3 : Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick (assuming Java is your scripting language) is to use the return statement when you want to terminate further processing.

Question 4 : Can we implement an interface in a JSP?

Answer 4 : No

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

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

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

Answer 6 : 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 7 : Can we use the constructor,  instead of init(), to initialize servlet?

Answer 7 : 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 8 : Can you make use of a ServletOutputStream object from within a JSP page?

Answer 8 : No. You are supposed to make use of only a JSPWriter object (given to you in the form of the implicit object out) for replying to clients. A JSPWriter can be viewed as a buffered version of the stream object returned by response.getWriter(), although from an implementational perspective, it is not. A page author can always disable the default buffering for any page using a page directive as:

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

Answer 9 : 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 10 : How can a servlet refresh automatically if some new data has entered the database?

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

JSP Contributors

krishan

Share your email for latest updates

Name:
Email:

Our partners