JSP Learning (ii) JSP directives

Source: Internet
Author: User
Tags error status code

JSP directives

JSP directives (Directive) are designed for the JSP engine, and they do not directly produce any visible output, but simply tell the engine how to handle the rest of the JSP page.

Basic syntax format for JSP directives:<%@ directive Property name = "Value"%>

Three instructions:

    • page directive
    • Include directives
    • taglib directive
One, page directive

The full syntax of the page directive defined in the JSP 2.0 specification:

<%@ Page [language="Java"] [extends="Package.class"] [Import="{package.class | package.*}, ..."] [Session="true | false"] [Buffer="None | 8kb | sizekb"] [AutoFlush="true | false"] [IsThreadSafe="true | false"] [Info="text"] [ErrorPage="Relative_url"] [Iserrorpage="true | false"] [ContentType="MimeType [; Charset=characterset]" | "text/html; charset=iso-8859-1"] [pageencoding="CharacterSet | Iso-8859-1"] [iselignored="true | false" ] %>

For example:

<%@  Language= "java " page import=" java.util.*,java.io.*,java.sql.* " Span style= "COLOR: #ff0000" > errorpage = "/errorpage/error.jsp " Pageencoding= "utf-8" iserrorpage= "true" %>

In general, exception objects are not available in JSP pages, only the Iserrorpage property of the page directive is set to "true"(the default is False) To explicitly declare that a JSP page is an error-handling page before the exception object can be used in a JSP page.

Use the <error-page> tab in Web. XML to set up error handling pages for your entire application:
    • You can use the <error-page> element in the Web. XML file to set up error-handling pages for the entire application.
    • <error-page> elements have 3 sub-elements,<error-code>, <exception-type>, <location>
    • <error-code> child element specifies the error status code, for example:<error-code>404</error-code>
    • <exception-type> child element specifies the fully qualified name of the exception class, for example:<exception-type>java.lang.arithmeticexception</ Exception-type>
    • <location> child element specifies the path to the error-handling page starting with "/", for example:<location>/ErrorPage/404Error.jsp</location>
<?XML version= "1.0" encoding= "UTF-8"?><Web-appversion= "3.0"xmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  <Display-name></Display-name>      <welcome-file-list>    <Welcome-file>index.jsp</Welcome-file>  </welcome-file-list>    <!--processing page for 500 error -  <Error-page>      <Error-code>4500</Error-code>      < Location>/errorpage/500error.jsp</ Location>  </Error-page>  </Web-app>

500error.jsp ( custom error page of size preferably more than 1024bytes, otherwise ie may not jump )

<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><HTML>  <Head>    <title>500 (server error) error friendly tip page</title>    <!--Auto Jump back to page after 3 seconds -    <Metahttp-equiv= "Refresh"content= "3;url=${pagecontext.request.contextpath}/index.jsp">  </Head>  <Body>    <imgalt= "Sorry, the server is wrong, please contact the administrator to resolve!" "src= "${pagecontext.request.contextpath}/img/500error.png"/><BR/>3 seconds after the automatic jump back to the page, if there is no jump, please click<ahref= "${pagecontext.request.contextpath}/index.jsp">Over here</a>  </Body></HTML>
Ii. include directives

Syntax:<%@ include file= "Relativeurl"%>, where the file property is used to specify the path to the introduced files. The path begins with "/" and represents the current web app.

<j@include > statements that contain other file contents to their own pages are called static inclusions.

The <jsp:include> directive is dynamically included , and if the contained page is a JSP, it is processed before the result is included, and if it contains a non-*.jsp file, it simply contains the contents of the file statically. Functions similar to @include

Iii. taglib directive

<%@ taglib uri= "uritotaglibrary" prefix= "TagPrefix"%>

<% @ taglib%> directive declares that this JSP file uses a custom label, references the tag library, and also specifies the prefix of their tag

JSP Learning (ii) JSP directives

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.