Previous | Home | Next |
JSP directives
In jsp directives are used to tells the web container which is translate a JSP page in servlet.
Three types Directives:
- page directive
- include directive
- taglib directive
Syntax used
<%@ directive attribute="value" %>
JSP page directive
In page directive is defines of the attributes which apply in an entire JSP page.
Syntax used
<%@ page attribute="value" %>
Attributes used
- import
- contentType
- extends
- info
- buffer
- language
- isELIgnored
- isThreadSafe
- autoFlush
- session
- pageEncoding
- errorPage
- isErrorPage
- import
- contentType
- extends
- info
- buffer
- language
- isELIgnored
- errorPage
- isErrorPage
It is used to import class which is connect of all package with similar to import keyword in java class or interface.
Example
<html>
<body>
<%@
page import="java.util.Date" %>
Today is: <%= new Date( ) %>
</body>
</html>
In contentType attribute is used the MIME(Multipurpose Internet Mail Extension) which is HTTP response and performed "text/html;charset=ISO-8859-1".
Example
<html>
<body>
<%@
page contentType=application/msword
%>
Today is: <%= new java.util.Date() %>
</body>
</html>
It is performed the parent class for inherited by servlet.
It is sets the information of the JSP page when it is inherite by perform with getServletInfo() method of Servlet interface.
Example
<html>
<body>
<%@
page info="composed by Sonoo Jaiswal" %>
Today is: <%= new java.util.Date() %>
</body>
</html>
In web container can be create method getServletInfo() for resulting servlet.
Example
public String
getServletInfo() {
return "composed by Sonoo
Jaiswal";
}
It makes sets the buffer size(kilobytes) which is handle output by the JSP page and default buffer size is 8Kb.
Example
<html>
<body>
<%@
page buffer="16kb" %>
Today is: <%= new java.util.Date() %>
</body>
</html>
It is specified of the scripting language.
In this attribute to be ignore the Expression Language (EL) in jsp by the isELIgnored attribute. By default its value is false i.e. Expression Language is enabled by default. We see Expression Language later.
<%@ page isELIgnored="true" %>//Now EL
will be ignored
In this attribute is performed Servlet and JSP both are multithreaded and you want to control this behaviour of JSP page, you can use isThreadSafe attribute of page directive.
In isThreadSafe value is true then you make it false, the web container will serialize the multiple requests.
<%@ page isThreadSafe="false" %>
The web container in such a case, will generate the servlet as:
public class SimplePage_jsp extends HttpJspBase
implements SingleThreadModel{
.......
}
The errorPage attribute is used to define the error page, if exception occurs in the current page, it will be redirected to the error page.
Example of errorPage attribute
//index.jsp
<html>
<body>
<%@
page errorPage="myerrorpage.jsp" %>
<%=
100/0
%>
</body>
</html>
The isErrorPage attribute is used to declare that the current page is the error page. Note: The exception object can only be used in the error page.
Example of isErrorPage attribute
//myerrorpage.jsp
<html>
<body>
<%@
page isErrorPage="true" %>
Sorry an exception occured!<br/>
The exception is: <%= exception %>
</body>
</html>
Previous | Home | Next |