>> Thursday, June 16, 2011
Q).How to refer the "this" variable within a JSP page?
A).Under JSP 1.0, the "page" implicit object page is equivalent to "this", and returns a reference to the servlet generated by the JSP page.
Q).What is the difference between <%@ include ...> (directive include) and <jsp:include> ?
A).The include directive :-
<%@ include file="fileName" %>
is static and processed at the time when the JSP page is translated into its equivalent servlet. The file included in the page at the time translation and compiled file also contain the included file code. This directive is normally used for including static resources only - like, banner, header, footer, etc. If you make some changes in the included file then it will not affect those files which had included this file.
The include action :-
<jsp:include page="relativeURL" />
is dynamic and processed at runtime. This will simply make a function call at run time to the included file. This action allows additional parameters to be passed via <jsp:param> child element of this include action element. If you make some changes in the included file then it will also affect those files which had included this file.
Q).How can I implement a thread-safe JSP page?
A).To make your JSPs thread-safe, you hace to implement the SingleThreadModel interface.
This can be done by using page directive with isThreadSafe attribute by setting it to false:
<%@ page isThreadSafe="false" %>
Q).What is difference between custom JSP tags and beans?
A).JSP has its own tag library that you can use in any nuber of pages. You can also create your own tags (Cusustom tags), define attributes and body of the tags and then group your tags into collections called tag library.
To use custom JSP tags, you need to define three separate components:
* Tag handler class.
* Tag library descriptor file.
* JSP file that uses the tag library.
When the first two components are done, you can use the tag by using taglib directive.
JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. Custom tags and beans accomplish the same goals � encapsulating complex behavior into simple and accessible forms.
Difference between custom JSP tags and beans :
* Custom tags require more work to set up than do beans.
* Custom tags can manipulate JSP content, beans cannot.
* 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.
Q).What is the differecnce between JspWriter and PrintWriter?
]A).JspWriter is a buffered version of the PrintWriter. JspWriter also differs from a PrintWriter by throwing java.io.IOException, which a PrintWriter does not. If the page is not buffered, output written to this JspWriter object will be written through to the PrintWriter directly, which will be created if necessary by invoking the getWriter() method on the response object. But if the page is buffered, the PrintWriter object will not be created until the buffer is flushed and operations like setContentType() are legal. Since this flexibility simplifies programming substantially, buffering is the default for JSP pages.
A).Under JSP 1.0, the "page" implicit object page is equivalent to "this", and returns a reference to the servlet generated by the JSP page.
Q).What is the difference between <%@ include ...> (directive include) and <jsp:include> ?
A).The include directive :-
<%@ include file="fileName" %>
is static and processed at the time when the JSP page is translated into its equivalent servlet. The file included in the page at the time translation and compiled file also contain the included file code. This directive is normally used for including static resources only - like, banner, header, footer, etc. If you make some changes in the included file then it will not affect those files which had included this file.
The include action :-
<jsp:include page="relativeURL" />
is dynamic and processed at runtime. This will simply make a function call at run time to the included file. This action allows additional parameters to be passed via <jsp:param> child element of this include action element. If you make some changes in the included file then it will also affect those files which had included this file.
Q).How can I implement a thread-safe JSP page?
A).To make your JSPs thread-safe, you hace to implement the SingleThreadModel interface.
This can be done by using page directive with isThreadSafe attribute by setting it to false:
<%@ page isThreadSafe="false" %>
Q).What is difference between custom JSP tags and beans?
A).JSP has its own tag library that you can use in any nuber of pages. You can also create your own tags (Cusustom tags), define attributes and body of the tags and then group your tags into collections called tag library.
To use custom JSP tags, you need to define three separate components:
* Tag handler class.
* Tag library descriptor file.
* JSP file that uses the tag library.
When the first two components are done, you can use the tag by using taglib directive.
JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. Custom tags and beans accomplish the same goals � encapsulating complex behavior into simple and accessible forms.
Difference between custom JSP tags and beans :
* Custom tags require more work to set up than do beans.
* Custom tags can manipulate JSP content, beans cannot.
* 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.
Q).What is the differecnce between JspWriter and PrintWriter?
]A).JspWriter is a buffered version of the PrintWriter. JspWriter also differs from a PrintWriter by throwing java.io.IOException, which a PrintWriter does not. If the page is not buffered, output written to this JspWriter object will be written through to the PrintWriter directly, which will be created if necessary by invoking the getWriter() method on the response object. But if the page is buffered, the PrintWriter object will not be created until the buffer is flushed and operations like setContentType() are legal. Since this flexibility simplifies programming substantially, buffering is the default for JSP pages.