• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

JSP Interview Questions Answers

Question - 1 : - How do you delete a Cookie within a JSP?

Answer - 1 : - Cookie mycook = new Cookie("name","value"); response.addCookie(mycook); Cookie killmycook = new Cookie("mycook","value"); killmycook.setMaxAge(0); killmycook.setPath("/"); killmycook.addCookie(killmycook);

Question - 2 : - How can I declare methods within my JSP page?

Answer - 2 : - You can declare methods for use within your JSP page as declarations. The methods can then be invoked within any other methods you declare, or within JSP scriptlets and expressions. Do note that you do not have direct access to any of the JSP implicit objects like request, response, session and so forth from within JSP methods. However, you should be able to pass any of the implicit JSP variables as parameters to the methods you declare. For example: Another Example: file1.jsp: file2.jsp <%test(out);% >

Question - 3 : - Why is _jspService() method starting with an '_' while other life cycle methods do not?

Answer - 3 : - _jspService() method will be written by the container hence any methods which are not to be overridden by the end user are typically written starting with an '_'. This is the reason why we don't override _jspService() method in any JSP page.

Question - 4 : - Can you make use of a ServletOutputStream object from within a JSP page?

Answer - 4 : - 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 - 5 : - How do you pass control from one JSP page to another?

Answer - 5 : - Use the following ways to pass control of a request from one servlet to another or one jsp to another. The RequestDispatcher object ‘s forward method to pass the control. The response.sendRedirect method

Question - 6 : - What are the two kinds of comments in JSP and what's the difference between them ?

Answer - 6 : - <%-- JSP Comment --%> <!-- HTML Comment -->

Question - 7 : - What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?

Answer - 7 : - request.getRequestDispatcher(path): In order to create it we need to give the relative path of the resource context.getRequestDispatcher(path): In order to create it we need to give the absolute path of the resource.

Question - 8 : - What is the difference between ServletContext and PageContext?

Answer - 8 : - ServletContext: Gives the information about the container PageContext: Gives the information about the Request

Question - 9 : - What is difference between custom JSP tags and beans?

Answer - 9 : - Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components: 1. the tag handler class that defines the tag\'s behavior 2. the tag library descriptor file that maps the XML element names to the tag implementations 3. the JSP file that uses the tag library When the first two components are done, you can use the tag by using taglib directive: <%@ taglib uri="xxx.tld" prefix="..." %> Then you are ready to use the tags you defined. Let's say the tag prefix is test: MyJSPTag or JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags to declare a bean and use to set value of the bean class and use to get value of the bean class. <%=identifier.getclassField() %> Custom tags and beans accomplish the same goals -- encapsulating complex behavior into simple and accessible forms. There are several differences: Custom tags can manipulate JSP content; beans cannot. Complex operations can be reduced to a significantly simpler form with custom tags than with beans. Custom tags require quite a bit more work to set up than do beans. Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.

Question - 10 : - Can I stop JSP execution while in the midst of processing a request?

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

Computer Contributors

Rajeev Katiyar
Yes Baroda

Share your email for latest updates


Our partners