Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commonly used JSP instructions in JSP

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces which JSP instructions are commonly used in JSP. It is very detailed and has a certain reference value. Friends who are interested must read it!

The use of JSP instructions in JSP development programs is very common, let's start to learn about it

< JSP directive mso-hansi-font-family: "" > affects the overall structure of the servlet class. It is commonly used in the following forms:

< @ directive attribute= "value" >

Also, you can write multiple attributes in a single statement:

<% @ directive attribute1= "value1" attribute2= "value2" attributeN= "valueN" >

There are two main directive types:

Page, which allows you to do something similar to import classes, defining the superclass of servlet (Superclass)

Mso-hansi-font-family: "" > etc.

Include, which allows you to insert files into the servlet class (when JSP files are translated into servlet).

1. JSP page Directive of JSP instruction

Syntax:

<% @ 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 attributes:

(1) import = "package.class" or import = "package.class1,..,package.classN".

Mso-hansi-font-family: "" >

You can definitely want the packages of import. For example:

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

The import attribute is one of these attributes that can appear multiple times in a JSP.

(2) contenType = "MIME=Type" or contentType= "MIME-Type;charset=Character-Set" mso-hansi-font-family: "" >

It specifies the MIME type of the output. Default is "text/html". For example:

<% @ page contentType= "text/plain"% > "

In scriptlet, it is equivalent to:

< response.setContentType ("text/plain"); >

(3) isThreadSafe = "true | false" A value of "true" (the default) indicates that normal servlet processing will occur and multiple requests will be processed in parallel by a single servlet instance, in which case the programmer will access multiple instance variables synchronously. A value of "false" indicates that servlet will implement single-threaded mode (SingleThreadModel), providing separate servlet instances regardless of whether the requests are submitted sequentially or concurrently.

(4) session= "true | false". A value of "true" (the default) means that the predefined variable session (inheriting HttpSession) should be bound to an existing session, otherwise one should be created and bound. A value of "false" means that the session variable will not be used, and if you try to use it, an error will occur when converting JSP to servlet.

(5) buffer = "sizekb | none". Determines the size of the buffer for JspWriter output. It depends by default on the server, but at least there must be 8kb.

(6) autoflush= "true | false" A value of "true mso-hansi-font-family:" > "(the default) means that it will be emptied automatically when the buffer is full, and a value of" false mso-hansi-font-family: "" > "means that an exception is thrown when the buffer is full, which is rarely used. It is illegal to use the false mso-hansi-font-family: "" > value when buffer= "none".

(7) extends= "package.class". This will generate a superclass for servlet. Please use this feature with special caution, because the server may already have one defined.

(8) info = "message" Define a string that can be obtained by calling the getServletInfo method.

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

(10) isErrorPage = "true | false" Specifies whether the current page can handle errors from another page. The default is "false".

(11) language = "java" mso-hansi-font-family: ">. Indicate the language that will be used below. However, don't worry about this attribute, because "java mso-hansi-font-family:" > "is both the default and legal choice.

2. JSP include Directive of JSP instruction

This directive allows you to include a file when JSP is converted to servlet. Syntax:

< jsp:include page= "{relativeURL | <% = expression% >}" flush= "true" / > mso-hansi-font-family: "; mso-font-kerning: 0pt" > or < jsp:include page= "{relativeURL | <% = expression% >}" flush= "true" > < jsp:param name= "parameterName" value= "{parameterValue | <% = expression% >}" / > + < / jsp:include >

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

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

< HTML > < HEAD > < TITLE > JSP tutorial < / TITLE > < / HEAD > < BODY > <% @ include file= "/ navbar.html"% >

Share To

Development

© 2024 shulou.com SLNews company. All rights reserved.

12
Report