JSP Introductory Beginner Tutorial JSP directives

Source: Internet
Author: User
Tags define expression flush include relative variable
The js| tutorial <jsp directive mso-hansi-font-family: "" to affect the overall structure of the servlet class. It is often used in the following forms:

<%@ directive attribute= "value"%>
  
Also, you can write multiple properties in one statement:

<%@ directive attribute1= "value1" attribute2= "value2" attributen= "Valuen"%>

There are two main types of directive:

page, which allows you to do something like import classes, define a servlet superclass (superclass),
Mso-hansi-font-family: "" "and so on;

Include, which allows you to insert files into the Servlet class (when the JSP file is translated as a servlet).

First, JSP page directive

Grammar:

<%@ page
[language= "Java"]
[extends= "Package. Class"]
[import= "{Package. Class |. *}, ..."]
[session= "True|false"]
[buffer= "none|8kb|sizekb"]
[autoflush= "True|false"]
[isthreadsafe= "True|false"]
[info= "Text"]
[errorpage= "Relativeurl"]
[contenttype= "mimetype [; Charset=characterset]" |
"Text/html; Charset=iso-8859-1 "]
[iserrorpage= "True|false"]

%>

Page directive mso-hansi-font-family: "" Allows you to define some case-sensitive properties:

(1) Import = "Package.class" or import = "Package.class1,.., package.classn".
Mso-hansi-font-family: "" > >

You can set the packages that you want to import. For example:

<%@ page import= "java.util.*"%>

The Import property is the only one of these properties that can appear multiple times in one JSP.

(2) Contentype = "Mime=type" or contenttype= "Mime-type;charset=character-set" mso-hansi-font-family: "" "

that specifies the MIME type of the output. The default is "text/html". For example:

<%@ page contenttype= "Text/plain"%> "

In Scriptlet is equivalent to:

<% Response.setcontenttype ("Text/plain"); %>

(3) IsThreadSafe = "true | False. If the value is "true" (the default), the normal servlet processing will be performed and multiple requests will be processed in parallel by a servlet instance, in which case the programmer synchronizes access to multiple instance variables. A value of "false" indicates that the servlet implements single-threaded mode (Singlethreadmodel), providing different detached servlet instances, whether the request is sequential or concurrent.

(4) session= "true | False ". If the value is "true" (the default), the predefined variable session (inherited HttpSession) should be bound to an existing session, or it should be created and bound. A value of "false" means that the session variable will not be used and an error occurs when the JSP converts to the servlet if you attempt to use it.

(5) buffer = "SIZEKB | None ". Determines the size of the buffer for the JspWriter output. The default is set by the server, but at least 8kb.

(6) autoflush= "true | False ". If the value is "True mso-hansi-font-family:" ">" (default), it will automatically empty when the buffer is full, and the value is "false mso-hansi-font-family:" "" > "when the buffer is full and an exception is passed, this is rarely used." When buffer= "None" is false mso-hansi-font-family: "" > value is not legal.

(7) extends= "Package.class". This will generate a superclass for the servlet. Use this feature with special care, because the server may have defined one.

(8) Info = "message". Defines a string that can be obtained by invoking the Getservletinfo method.

(9) ErrorPage = "URL". Specify a JSP mso-hansi-font-family: "" > page to handle any unexpected errors that can be thrown but not handled by the current page.

(a) Iserrorpage = "true | False ". Specifies whether the current page can handle errors from another page, and defaults to "false".

(one) language = "java" mso-hansi-font-family: "". Indicate the language that will be used below. However, it is not necessary to bother with this attribute, because "java mso-hansi-font-family:" ">" is both the default and the only legitimate choice.

Two JSP include directive this directive allows you to include a file when the JSP is converted to a servlet. Grammar:

mso-hansi-font-family: "; mso-font-kerning:0pt" > or
Value= "{parametervalue | <%=expression%>}"/>+

URL mso-hansi-font-family: "" is usually relative to the JSP page that points to it, but, generally use relative "URL", you can use a slash "/" as the beginning of the URL to inform the system URL mso-hansi-font-family: "" > The main path of the relative Web server. The included files will be parsed in the form of a regular JSP, so you can use static html,scripting elements,directives, and actions in them.

Let's take a look at an example where many sites contain a small navigation bar on each page. It usually appears on the top or left side of the page and is included in each page. It's natural to implement this with include directive, and it's a nightmare to use regular HTML mso-hansi-font-family: "" To copy these statements to every page. Please see the following code:



JSP Tutorials


<%@ include file= "/navbar.html"%>



Because the file is inserted when the page is converted, if the navigation bar changes, you need to recompile all the JSP mso-hansi-font-family: "" "" ". If your navigation bar does not often change this is undoubtedly efficient, but if your included file changes frequently, it is recommended that you use the Jsp:include action (later) to replace it when the page is requested to include the file.


Related Article

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.