ArticlesTutorialsInterview Questions & AnswersCertificationsFree Books & Sample ChaptersTechnical Discussions  Your Account | Advertise with us | Feedback |
Few pages of this site are under construction and we are constantly trying to improve it. If you have any suggestions or ideas about how to improve the site, please Let us know.
JSP Interview Questions


add to:
Del.icio.us
Digg
Google
Spurl
Slashdot
Y! MyWeb
Blink
Furl
 
11.What is page directive?

  • A page directive is to inform the JSP engine about the headers or facilities that page should get from the environment.
  • Typically, the page directive is found at the top of almost all of our JSP pages.
  • There can be any number of page directives within a JSP page (although the attribute – value pair must be unique).
  • The syntax of the include directive is: <%@ page attribute="value">
  • Example:<%@ include file="header.jsp" %>


12.What are the attributes of page directive?

There are thirteen attributes defined for a page directive of which the important attributes are as follows:

  • import: It specifies the packages that are to be imported.
  • session: It specifies whether a session data is available to the JSP page.
  • contentType: It allows a user to set the content-type for a page.
  • isELIgnored: It specifies whether the EL expressions are ignored when a JSP is translated to a servlet.


13.What is the include directive?

There are thirteen attributes defined for a page directive of which the important attributes are as follows:

  • The include directive is used to statically insert the contents of a resource into the current JSP.
  • This enables a user to reuse the code without duplicating it, and includes the contents of the specified file at the translation time.
  • The syntax of the include directive is as follows:
    <%@ include file = "FileName" %>
  • This directive has only one attribute called file that specifies the name of the file to be included.


14.What are the JSP standard actions?

  • The JSP standard actions affect the overall runtime behavior of a JSP page and also the response sent back to the client.
  • They can be used to include a file at the request time, to find or instantiate a JavaBean, to forward a request to a new page, to generate a browser-specific code, etc.
  • Ex: include, forward, useBean,etc. object

15.What are the standard actions available in JSP?

The standard actions available in JSP are as follows:

  • <jsp:include>: It includes a response from a servlet or a JSP page into the current page. It differs from an include directive in that it includes a resource at request processing time, whereas the include directive includes a resource at translation time.
  • <jsp:forward>: It forwards a response from a servlet or a JSP page to another page.
  • <jsp:useBean>: It makes a JavaBean available to a page and instantiates the bean.
  • <jsp:setProperty>: It sets the properties for a JavaBean.
  • <jsp:getProperty>: It gets the value of a property from a JavaBean component and adds it to the response.
  • <jsp:param>: It is used in conjunction with <jsp:forward>;, <jsp:, or plugin>; to add a parameter to a request. These parameters are provided using the name-value pairs.
  • <jsp:plugin>: It is used to include a Java applet or a JavaBean in the current JSP page.

16.What is the <jsp:useBean> standard action?

The <jsp:useBean> standard action is used to locate an existing JavaBean or to create a JavaBean if it does not exist. It has attributes to identify the object instance, to specify the lifetime of the bean, and to specify the fully qualified classpath and type.


17.What are the scopes available in <jsp:useBean>?

The scopes available in <jsp:useBean> are as follows:

  • page scope:: It specifies that the object will be available for the entire JSP page but not outside the page.
  • request scope: It specifies that the object will be associated with a particular request and exist as long as the request exists.
  • application scope: It specifies that the object will be available throughout the entire Web application but not outside the application.
  • session scope: It specifies that the object will be available throughout the session with a particular client.


18.What is the <jsp:forward> standard action?
  • The <jsp:forward> standard action forwards a response from a servlet or a JSP page to another page.
  • The execution of the current page is stopped and control is transferred to the forwarded page.
  • The syntax of the <jsp:forward> standard action is : 
    <jsp:forward page="/targetPage" />
    Here, targetPage can be a JSP page, an HTML page, or a servlet within the same context.
  • If anything is written to the output stream that is not buffered before <jsp:forward>, an IllegalStateException will be thrown.

Note : Whenever we intend to use <jsp:forward> or <jsp:include> in a page, buffering should be enabled. By default buffer is enabled.


19.What is the <jsp:include> standard action?

The <jsp:include> standard action enables the current JSP page to include a static or a dynamic resource at runtime. In contrast to the include directive, the include action is used for resources that change frequently. The resource to be included must be in the same context.The syntax of the <jsp:include> standard action is as follows:
<jsp:include page="targetPage" flush="true"/>
Here, targetPage is the page to be included in the current JSP.


20.What is the difference between include directive and include action?

Include directive Include action
The include directive, includes the content of the specified file during the translation phase–when the page is converted to a servlet. The include action, includes the response generated by executing the specified page (a JSP page or a servlet) during the request processing phase–when the page is requested by a user.
The include directive is used to statically insert the contents of a resource into the current JSP. The include standard action enables the current JSP page to include a static or a dynamic resource at runtime.
Use the include directive if the file changes rarely. It’s the fastest mechanism. Use the include action only for content that changes often, and if which page to include cannot be decided until the main page is requested.


Back to top

Test

  ALSO SEE :

About Us | Our Mission | Terms of use | Author Terms |    Search        | Contact Us | Advertise With Us | Link to Us | Sitemap
Copyright © 2016 developersBOOK.COM. All rights reserved.