"jsp" JSP directives

Source: Internet
Author: User
Tags tld

JSP instruction Description: 1, The JSP instruction is used to tell the JSP engine to interpret the conversion parameters of the jsp, they do not produce output information, only during the translation and compilation of the JSP Function. 2, JSP instructions must be written in the specified format: <%@ [goes here]%>3, In addition to the include directive, page and taglib instructions must be written at the beginning of the JSP File. JSP directives are mainly 3 page, include, taglib, The following describes the page directive page directive is composed of many k-v forms of attributes, In addition to the import property, the other properties can only appear once.
Language = "java" You can only use Java at this time, the default is Good.
extends = "className" Specifies the parent class of the translated servlet, which is usually specified by the JSP engine, so do not use this property, which is good by default.
Isthreadsafe= "true" The default is true, do not modify this property, the default is Good. The official has strongly deprecated setting it to false. If false, multiple requests execute the service method serially.
AutoFlush = "true|false" If true, the stream is automatically refreshed when the output stream of the Out object is cached full, and the buffered data is written to the response Body. If false, an exception is thrown when the output stream of an Out object is cached Full. The default is true, which is good by default.
iselignored = "false | True Whether the El expression for this JSP page is Enabled. If true, the El for this JSP page will not take Effect. If false, the El can be used on this JSP page. The default is false, which is good by default.
info= "" The description information of JSP page can be obtained by getservletinfo. Dispensable. The default is Good.
Buffer = "none | 8kb| 16kb|, wait. The size of the output buffer for the JspWriter object Out. Default is 8KB
Iserrorpage= "true | False

Indicates whether the current JSP is a page for handling errors, and if true, this JSP can be set to the value of the errorpage of other jsps.

And implicit object exception can be used in this jsp.

ErrorPage = "error_page_url" Specifies the error handling page that is forwarded when an exception, error occurs. Error_page_url is the relative address.  For example, The exception handling page is written under Web/errorhandlejsps 500.jsp. Errorpage= "web-inf/errorhandlejsps/500.jsp"
import = "java.util.*,java.io.*" That is, importing the Package. The Import property can appear multiple times in a JSP page (other occurrences can occur only once). For example <%@ page import= "java.io.*"% > <%@ page import= "java.util.*"% >
Session = "true | False Indicates whether this JSP page needs to use the Session. If true, the implicit object session is the reference to the current session Object. also, If the session object was not created before this JSP page uses session, it is automatically created and has an implicit object session referencing the session Object. If false, the page cannot use session, (session is null), and the session object is not actively generated. The default is True
Contenttype= "text/html;charset=utf-8" The MIME type of the response Document. will become the Response.setcontenttype ("xxxxxxxx") in the service method in the transferred servlet
pageencoding= "utf-8" Defines the character encoding for this JSP page when it is Saved. Default is Iso-8859-1
trimdirectivewhitespaces= "true|false"

The default is false, which is set to true after the effect is as Follows:

The include directive is statically contained, and the contents of the contained file will be merged into the JSP file during the translation (the insertion position of the merge is where the incude instruction is located), and the result is as if the contents of the contained file were originally written in the jsp. <% @include file= "relative path URL of the contained file"%> if the URL starts with a/, the path is relative to the Web root path if it does not start with/, relative to the path that currently contains the jsp. The included pages can be html,xml,jsp and so On. Use: 1, We can write the copyright information at the bottom of the page in a separate JSP file, and then other pages if you need to display the copyright information at the bottom of the page, you can include the past through the include Directive. 2. The include directive can appear at any time and anywhere in the JSP Page. So he is often used to build view template skeletons for view layers, such as head, foot Navi can be detached and use include Inclusion. Include is useful when the content of a Web page is a fixed pattern, and only part of it Changes. ExampleFiles: index.jsp
<%@ PageContentType= "text/html; Charset=utf-8 "pageencoding= "UTF-8"trimdirectivewhitespaces= "true"Session= "true"%><!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "content-type"content= "text/html; charset=utf-8"><title>Title</title></Head><Body><H1>Welcome</H1><P>La la la la la</P><%@ includefile= "/web-inf/jspf/copyright.jsp" %></Body></HTML>

Files: copyright.jsp

location:/web-inf/jspf/copyright.jsp

 <  %@ page  pageencoding  = "UTF-8"  %  >  <  div  style  = "width:1000px;height:100px;background: #F0F0F0"  >  <  p  style  = "text-align:center;"  >  I am the copyright information </ p  >  </ div  >  

TAGLIB directive Taglib As the name implies is a library of some label Formation. Each of these tags has its own execution logic, which is the encapsulation of complex Java Code. Using these tags is written in XML syntax and is therefore friendly to the front-end staff. Use the Tablig directive to import a tag library in a JSP page before you can use it.
<uri= "taglibraryurl"  prefix= "tagPrefix"  %  >
Uri: the path to the tag library. If the tag library is given as a jar package, it is filled with a url. Prefix: the prefix of the tag library.  Each tag library has a recommended value (preferred), which is generally used to facilitate agreement with other Programmers. For example: the tag library is given as a jar package <%@ taglib prefix = "c" uri= "http://java.sun.com/jsp/jstl/core"%> for example: the tag library is not packaged, but exists in the Project. URI specifies the path of the TLD file under the WEB root directory <%@ taglib uri= "/web-inf/tlds/mytaglib.tld" prefix= "myprefix"%>

Examples of <c:if> tags using jstl
<%@ PageContentType= "text/html; charset=utf-8"pageencoding= "utf-8"trimdirectivewhitespaces= "true"Session= "true"%><%@ taglibprefix= "c"URI= "http://java.sun.com/jsp/jstl/core"%><!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "content-type"content= "text/html; charset=utf-8"></Head><Body>    <!--If the user exists, the shopping cart and personal center are displayed -                <c:ifTest= "${sessionscope.user!=null}">        <Li>Shopping Cart</Li>        <Li><ahref= "usercenter.jsp">Personal Center</a></Li>    </c:if></Body></HTML>

"jsp" 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.