Ads 468x60px

Pages

Thursday, 28 June 2012

servlets interview questions


13)How will you include a static file in a JSP page?
You can include a static resource to a JSP using <jsp:directive > or <%@ inlcude >.

14)How you can perform browser redirection?
We can use the method sendRedirect of HttpServletResponse or forward method of RequestDispatcher

15)Can we use  ServletOutputStream object from a JSP page?
No. You are supposed to use JSPWriter object (given to you in the form of the implicit object out) only for replying to clients.

16)How can you stop JSP execution in the middle of processing a request?
We can use the return statement to stop the processing of JSP. Because JSP is compiled to servlet and all the statements will go inside service method, any time you can stop the processing using return statement.

17)How can I invoke a JSP error page from a servlet? You can invoke the JSP error page and pass the exception object to it from within a servlet. For that you need to create a request dispatcher for the JSP error page, and pass the exception object as a javax.servlet.jsp.jspException request attribute

18)How does JSP handle runtime exceptions? Using errorPage attribute of page directive JSP handles runtime exceptions. We need to specify isErrorPage=true if the current page is intended to use as a JSP error page.

19)What is the difference between JSP and Servlets ?
JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.

20) What is difference between custom JSP tags and beans?
 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: the tag handler class that defines the tag's behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library

JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags

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.

21) What are the different ways for session tracking?
Cookies, URL rewriting, HttpSession, Hidden form fields

22)What mechanisms are used by a Servlet Container to maintain session information?
Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information

23)Difference between GET and POST?
 In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL.

0 comments:

Post a Comment