41 . Explain about autoflush?
This command is used to autoflush the contents. If a value of true is used it indicates to flush the buffer whenever it is full. In case of false it indicates that an exception should be thrown whenever the buffer is full. If you are trying to access the page at the time of conversion of a JSP into servlet will result in error.
42. How do you restrict page errors display in the JSP page?
You first set "errorPage" attribute of PAGE directive to the name of the error page (ie errorPage="error.jsp")in your jsp page .
Then in the error.jsp page set "isErrorpage=TRUE".
When an error occur in your jsp page, then the control will be automatically forward to error page.
43. What are the different scopes available fos JSPs ?
There are four types of scopes are allowed in the JSP.
- page - with in the same page
- request - after forward or include also you will get the request scope data.
- session - after senRedirect also you will get the session scope data. All data stored in session is available to end user till session closed or browser closed.
- application - Data will be available throughout the application. One user can store data in application scope and other can get the data from application scope.
44. when do use application scope?
If we want to make our data available to the entire application then we have to use application scope.
45. What are the different scope valiues for the <jsp:useBean>?
The different scope values for <jsp:useBean> are
1. page
2. request
3.session
4.application
46. How do I use a scriptlet to initialize a newly instantiated bean?
jsp:useBean action may optionally have a body. If the body is specified, its contents will be automatically invoked when the specified bean is instantiated. Typically, the body will contain scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not restricted to using those alone.
The following example shows the "today" property of the Foo bean initialized to the current date when it is instantiated. Note that here, we make use of a JSP expression within the jsp:setProperty action.
<jsp:useBean id="foo" class="com.Bar.Foo" >
<jsp:setProperty name="foo" property="x"
value="<%=java.text.DateFormat.getDateInstance().format(new java.util.Date()) %>" / >
<%-- scriptlets calling bean setter methods go here --%>
</jsp:useBean >
47 . Can a JSP page instantiate a serialized bean?
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-INF/jspbeans directory for it to be located by the JSP engine.
48.How do we include static files within a jsp page ?
We can include static files in JSP by using include directive (static include)
<%@ include file="header.jsp" %>
The content of the header.jsp will be included in the current jsp at translation time. Hence this inclusion is also known as static include.
49.In JSPs how many ways are possible to perform inclusion?
In JSP, we can perform inclusion in the following ways.
- By include directive:
<%@ include file="header.jsp" %>
The content of the header.jsp will be included in the current jsp at translation time. Hence this inclusion is also known as static include.
- By include action:
<jsp:include page="header.jsp" />
The response of the jsp will be included in the current page response at request processing time(run time) hence it is also known as dynamic include.
- by using pageContext implicit object
<%
pageContext.include("/header.jsp");
%>
This inclusion also happened at request processing time(run time).
- by using RequestDispatcher object
<%
RequestDispatcher rd = request.getRequestDispatcher("/header.jsp");
Rd.incliude(request,response);
%>
50.In which situation we can use static include and dynamic include in JSPs ?
If the target resource ( included resource) won't change frequently, then it is recommended to use static include.
<%@ include file="header.jsp" %>
If the target resource(Included page) will change frequently , then it is recommended to use dynamic include.
< jsp:include page="header.jsp" />
0 comments:
Post a Comment