Directive Tags
Directive tags
-->These tags gives direction to jsp page compiler towards generating code in JES class
Syntax
- <%@ Directive tag attribute %>
-->The three directive tags:-
1.)Page directive
-->To provide various inputa to jsp page like buffersize, contentType and etc..)
2.)Include directive
-->To include content of a file to jsp page
3.)Tag lib directive
-->To use Taglib libraries (it is library that contains set of jsp tags)
(1)Page Directive
Standard syntax
- <%@page attributes %>
Xml syntax
- <jsp:directive.page attributes %>
Attributes
Import, info, contentType, buffer, autoFlush, session, extends, isELIgnored, isThreadSafe, errorPage, isErrorPage and etc...
1.)Import
-->Useful to import packages in JES class
-->Use these attribute to import other than servlet-api, jsp-api related packages
-->We can specify these attribute for multiple times either in same <%@page%> tag or multiple <%@page%>tag
- E.g:
- <%@page import="java.sql.*, java.net.*"%>
- E.g:
- <%@page import="java.sql.*, java.util.*"%>
- E.g:
- <%@page import="java.sql.*"%>
- <%@page import="java.net.*"%>
2.)contentType
-->Given to specify MIME type as the response content type for jsp. It internally calls res.setContentType(-) method in JES class
E.g:
- <%@page contentType="text/xml"%>
Note: The default value of this attribute is "text/html"
-->If we call <%response.setContentType(-)%> explicitly then the contentType specified here will be taken as the final response content type for jsp
3.)Info
-->Useful to write short description about jsp page
-->Useful to know purpose of jsp page by seeing header section of the jsp page, internally overrides' getServletInfo() method having this short description
test.jsp
- <%@page info="test jsp page"%>
In JES class
- publi class test_jsp extends..{
- public String getServletInfo(){
- return "test jsp page"
- }
- }
4.)Session
-->Specifies whether the implicit object session should be created or not
- <%@page session="false"%>
-->The implicit object session will not be created
- <%@page session="true"%>
-->The implicit object session will be created
-->Generally we need session object only in session tracking otherwise session object need is optional in jsp
5.)extends
-->Allows to specify super class for JES class to get some control on JES class execution. This class must extends from HttpServlet and must implement from HttpJspPage(I) having servlet life cycle methods internally calling jsp life cycle methods
-->Developing these class is very complex, so these is not a recommended attribute to use
- <%@page extends="TestBase"%>
JES class
- public class first_jsp extends TestBase{
- ...
- }
Note: It is recommended to use container supplied java class as the super class of JES class
6.)buffer
-->Buffer is temporary memory that holds data for temporary period
-->servlet component writes it's output directly to response object without buffer whereas jsp component takes the support of buffer whose default size is 8kb as shown below
-->The content return to buffer will be flushed to response object when buffer is fully filled up or when it is flushed out explicitly or execution of the code placed in jsp is completed
-->Allows to specify the above discussed jsp buffer size, even useful to disabled buffer, default size is 8kb
E.g
- <%@page buffer="10kb"%>
- -->Enables 10kb buffer
- <%@page buffer="none"%>
- -->Disables the buffer(jsp component directly qrites the output to response object)
7.)autoflush
-->The process of sending buffer content to it's real destination (response obj) is called flushing. Jsp component /container automatically flushes the content of buffer once buffer is filled up or when jsp execution is completed because the default value of autoFlush attribute is true
E.g:
- <%@page buffer="10kb" autoFlush="true"%>
E.g:
- <%@page buffer="none" autoFlush="false"%>
- -->Gives badCombo Error (we can't disable autoflush when buffer is not there)
E.g:
- <%@page buffer="1kb" autoFlush="false"%>
- <% for (int i=1;i<=1000;i++){
- out.println("tej"+i);
- }
- %>
Raises IOException Error: JSP Buffer overflow
Solution
Either enable autoFlush="true" or explicitly call out.flush(-) inside the for loop
E.g:
- <%@page buffer="1kb" autoFlush="false"%>
- <% for (int i=1;i<=1000;i++){
- out.flush();
- out.println("tej"+i);
- }
- %>
Comments
Post a Comment
Express your feelings