In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the example analysis of JSP grammar, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
HTML comment
Displays a comment on the client side.
JSP syntax
You can write comments at will, but do not use "- -% >". If you must use "- -% >", use "- -% >".
=
Statement
Declare legal variables and methods in JSP programs
JSP syntax
Examples
Description
Declare the variables and methods you will use in the JSP program. You must do the same, or you will make a mistake.
You can declare multiple variables and methods at once, as long as they end with ";", of course, if these declarations are legal in Java.
When you declare a method or variable, pay attention to the following rules:
The declaration must end with ";" (Scriptlet has the same rules, but the expression is different).
You can directly use the declared variables and methods that are included in without redeclaring them.
A declaration is valid only on one page. If you want to use some declarations on each page, it's best to write them into a separate file, and then use or
The element is included.
=
Expression.
Contains an expression that conforms to the JSP syntax
JSP syntax
Examples
.
Description
The expression element represents an expression defined in the scripting language, which is automatically converted to a string after running, and then inserted into the location of the expression displayed in the JSP file. Because the value of this expression has been converted to a string, you can insert the expression in a line of text (in exactly the same form as ASP).
Keep the following points in mind when using expressions in JSP:
You cannot use a semicolon (";") as the end of an expression. But the same expression used in scriptlet needs to end with a semicolon! View Scriptlet
This expression element can include any expression that is valid in Java Language Specification.
Sometimes expressions can also be used as attribute values for other JSP elements. An expression can become very complex, and it may consist of one or more expressions in the order from left to right.
=
Scriptlet
Contains a valid program segment.
JSP syntax
Examples
Description
A scriptlet can contain multiple jsp statements, methods, variables, and expressions
Because of scriptlet, we can do the following:
Declare the variable or method to be used (refer to the declaration).
Write JSP expressions (reference expressions).
Use any implied object and any declared object with
Write JSP statements (if you are using the Java language, these statements must comply with Java Language Specification,).
Any text, HTML tags, JSP elements must be outside the scriptlet
When the JSP receives a customer's request, the scriptlet is executed, and if the scriptlet has displayed content, the displayed content is stored in the out object.
=
Include command
Include a static file in JSP and parse the JSP statements in the file.
JSP syntax
Examples
Include.jsp:
An Include Test
The current date and time are
Date.jsp:
Displays in the page:
The current date and time are
Aug 30, 1999 2:38:40
Description
Instruction will insert a file containing text or code at JSP compilation time, and when you use instruction, the inclusion process is treated as static. Static inclusion means that the included file will be inserted into the JSP file, which can be a JSP file, a HTML file, or a text file. If the JSP file is included, the code in the file that contains the JSP will be executed.
If you just use include to include a static file. Then the results executed by the included file will be inserted into the JSP file where it is placed. Once the include file is executed, the process of the main JSP file will be resumed and proceed to the next line.
The included file can be a html file, a jsp file, a text file, or just a piece of Java code, but you have to be aware that you can't use the, tag in this include file, because this will affect the same tag in the original JSP file, and doing so can sometimes lead to errors.
Some instructive behaviors are based on special JSP compilation conditions, such as:
The included file must be open to all customers and must be valid f, or it has security restrictions
If the include file is changed, the JSP file containing the file will be recompiled
Attributes:
File= "relativeURL"
Generally speaking, the pathname of this containing file refers to the relative path, which does not require any port, protocol, or domain name, as follows:
"error.jsp" / templates/onlinestore.html "" / beans/calendar.jsp "
If the path starts with "/", then the path mainly refers to the context path of the JSP application, and if the path begins with a file name or directory name, then this path is the current path of the JSP file being used.
=
Page instruction
Define the global properties in the JSP file.
JSP syntax
Examples
Description
Directive acts on the entire JSP page, as well as static include files. But instructions cannot act on dynamic include files, such as
You can use multiple instructions in a page, but the attribute can only be used once, with one exception: the import attribute. Because the import property is similar to the import statement in Java (see Java Language), you can use this property a few more times.
No matter where you put the instruction in the JSP file, it covers the entire JSP page. However, for the readability of JSP programs and good programming habits, it is best to put it at the top of the JSP file.
Attribute
Language= "java"
To declare the type of scripting language, you can only use "java" for the time being.
Extends= "package.class"
Indicate the full name of the Java Class that needs to be added when JSP compiles, but use it carefully, it will limit the compilation ability of JSP.
Import= "{package.class / package.*},..."
A list of Java packages that need to be imported, which act on segments, expressions, and declarations.
The following package was imported at JSP compile time, so you don't need to specify it anymore:
Java.lang.*
Javax.servlet.*
Javax.servlet.jsp.*
Javax.servlet.http.*
Session= "true / false"
Set whether the customer needs HTTP Session. (anyone who has studied ASP should be familiar with it.) if it is true, then Session is useful.
If it has false, then you cannot use session objects and elements that define scope=session. Such use can lead to errors.
The default value is true.
Buffer= "none / 8kb / sizekb"
The size of the buffer is used by the out object to process the output of the executed JSP to the client browser. The default value is 8kb
AutoFlush= "true / false"
Set whether to force output if buffer overflows, if its value is defined as true (default), the output is normal, if it is set to false, if this buffer overflow, it will cause an unexpected error. If you set buffer to none, you cannot set autoFlush to false.
IsThreadSafe= "true / false"
Sets whether the Jsp file can be used by multiple threads. The default value is true, that is, JSP can process requests from multiple users at the same time. If set to false, a jsp can only process one request at a time.
Info= "text"
A text will be added verbatim to the JSP when JSP is executed, and you can retrieve it using the Servlet.getServletInfo method.
ErrorPage= "relativeURL"
Sets the JSP file that handles exception events.
IsErrorPage= "true / false"
Sets whether this page is an error page. If it is set to true, you can use the exception object.
ContentType= "mimeType [; charset=characterSet]" / "text/html;charset=ISO-8859-1"
Sets the MIME type. The default MIME type is text/html, and the default character set is ISO-8859-1.
=
Taglib instruction
Define a tag library and the prefix of its custom tags.
JSP syntax
Examples
.
.
Description
The directive declares that the JSP file uses custom tags, references the tag library, and specifies the prefix of their tags.
The custom tag here contains tags and elements. Because JSP files can be converted to XML, it is important to understand the relationship between tags and elements. The tag is just a slightly elevated tag that is part of the JSP element. The JSP element is part of the JSP syntax and has opening and closing tags like XML. Elements can also contain other text, tags, and elements. For example, a jsp:plugin element has opening and closing tags, as well as and elements.
You must use instructions before using custom tags, and you can use them multiple times on a page, but prefixes can only be used once.
Attribute
Uri= "URIToTagLibrary"
Uniform Resource Identifier (URI) uniquely names custom tags according to their prefixes, and URI can be the following:
Uniform Resource Locator (URL), defined by RFC 2396, view http://www.hut.fi/u/jkorpela/rfc/2396/full.html
Uniform Resource Name (URN), defined by RFC 2396
A relative or absolute path
Prefix= "tagPrefix"
The prefix before the custom tag, such as public in, is illegal if you don't write public here. Please do not use jsp, jspx, java, javax, servlet, sun, and sunw as your prefixes
=
Redirect a HTML file, JSP file, or a program segment.
JSP syntax
Or
+
Examples
Description
Tags pass a request object containing user requests from one JSP file to another. The code below the tag will not be executed.
You can pass parameters and values to the target file. In this example, the parameter we passed is called username and the value is scott. If you use tags, the target file must be a dynamic file that can handle parameters.
If you use unbuffered output, be careful when using it. If the jsp file already has data before you use it, then the file execution will go wrong.
Attribute
Page= "{relativeURL /}"
Here is an expression or a string indicating the file or URL you are going to direct. This file can be a JSP, a program segment, or any other file that can handle request objects (such as asp,cgi,php).
+
Send one or more parameters to a dynamic file, which must be a dynamic file.
If you want to pass multiple parameters, you can use multiple parameters in a JSP file. Name specifies the parameter name and value specifies the parameter value.
=
Gets the property value of Bean, which is used to display on the page
JSP syntax
Examples
Calendar of
Description
This element will get the attribute value of Bean and can be used or displayed in the JSP page. Before you can use it, you must create it with.
Elements have some limitations:
You cannot use it to retrieve an attribute that has already been indexed
You can use it with JavaBeans components, but not with Enterprise Bean.
Attribute
Name= "beanInstanceName"
The name of the bean, specified by
Property= "propertyName"
The property name of the specified Bean.
Tips:
It is mentioned in sun's JSP reference that if the value you use to retrieve is null, then NullPointerException will appear, and if you use a program segment or expression to retrieve its value, then null will appear on the browser.
=
Contains a static or dynamic file.
JSP syntax
Or
+
Examples
Description
Elements allow you to include dynamic files and static files, and the results of these two include files are different. If the file is only static, then this inclusion simply adds the contents of the included file to the jsp file, and if the file is dynamic, the included file will also be executed by the Jsp compiler (all similar to asp)
You can't tell from the file name whether a file is dynamic or static. For example, aspcn.asp may just contain some information and does not need to be executed. You can process both files at the same time, so you don't need to include them to determine whether the file is dynamic or static.
If the include file is dynamic, you can also pass parameter names and values using the.
Attribute
Page= "{relativeURL /}"
The parameter is a relative path, or an expression that represents a relative path.
Flush= "true"
Here you must use flush= "true", you cannot use false value. The default value is false
+
Clause allows you to pass one or more parameters to a dynamic file
You can use more than one in a page to pass multiple parameters.
=
Execute an applet or Bean and, if possible, download a Java plug-in to execute it.
JSP syntax
[
[] +
]
[text message for user]
Examples
Unable to load applet
Description
Elements are used to play or display an object (typically applet and Bean) in a browser, which requires the java plug-in in the browser.
When the Jsp file is compiled and sent to the browser, the element will be replaced with or element according to the browser's version. Note that for HTML 4. 0, for HTML 3. 2.
In general, the element specifies whether the object is Applet or Bean, as well as the name and location of the class, and where the Java plug-in will be downloaded. The details are as follows:
Attribute
Type= "bean / applet"
. The type of plug-in object to be executed, you have to specify whether this is Bean or applet, because this property has no default.
Code= "classFileName"
The name of the Java Class that will be executed by the Java plug-in must end with .class. This file must exist in the directory specified by the codebase attribute.
Codebase= "classFileDirectoryName"
The directory (or path) of the Java Class file that will be executed. If you do not provide this attribute, the directory of the jsp file used will be used.
Name= "instanceName"
The name of this Bean or applet instance, which will be called elsewhere in Jsp.
Archive= "URIToArchive,..."
Some pathnames separated by commas are used to preload some of the class to be used, which will improve the performance of applet.
Align= "bottom / top / middle / left / right"
The location of the drawing, object, Applet, has the following values:
Bottom
Top
Middle
Left
Right
Height= "displayPixels" width= "displayPixels"
The value of the length and width to be displayed by Applet or Bean, which is a number in pixels.
Hspace= "leftRightPixels" vspace= "topBottomPixels"
Applet or Bean display on the left and right side of the screen, the space left up and down, in pixels.
Jreversion= "JREVersionNumber / 1.1"
The version of Java Runtime Environment (JRE) required for Applet or Bean to run. The default value is 1. 1.
Nspluginurl= "URLToPlugin"
The download address of the JRE that Netscape Navigator users can use. This value is a standard URL, such as http://www.aspcn.com/jsp.
Iepluginurl= "URLToPlugin"
The download address of the JRE that IE users can use. This value is a standard URL, such as http://www.aspcn.com/jsp.
[] +
The parameter or parameter value that you need to pass to applet or Bean.
Text message for user
A paragraph of text is used to display to the user when the Java plug-in cannot be started. If the plug-in can start but applet or Bean cannot, then the browser will have an error message pop up.
=
Set the property value in Bean.
JSP syntax
Examples
Description
Element sets one or more property values in Bean using the setter method given by Bean. You must declare this Bean before you can use this element. Because, and are associated with each other, the names of the Bean instances they use should match (that is, the value of name in should be the same as the value of id in)
You can use a variety of ways to set attribute values:
Match attributes in Bean by all values entered by the user (as in the request object in the parameter store)
Matches the attributes specified in Bean by the specified values entered by the user
Use an expression to match the properties of Bean at run time
Each method of setting attribute values has its own specific syntax, which we will explain below.
Attribute and its usage
Name= "beanInstanceName"
Represents the name of the Bean instance that has been created in.
Property= "*"
Stores all values entered by the user in Jsp, which are used to match attributes in Bean. The name of the property in Bean must be the same as the parameter name in the request object.
The parameter values passed from the customer to the server are generally character types, and these strings must be converted to other types in order to match in Bean. The following table lists the types of Bean attributes and their conversion methods.
A method of converting a string into another type. Property Typ
Method
Boolean or Boolean
Java.lang.Boolean.valueOf (String)
Byte or Byte
Java.lang.Byte.valueOf (String)
Char or Character
Java.lang.Character.valueOf (String)
Double or Double
Java.lang.Double.valueOf (String)
Integer or Integer
Java.lang.Integer.valueOf (String)
Float or Float
Java.lang.Float.valueOf (String)
Long or Long
Java.lang.Long.valueOf (String)
If there is a null value in the parameter value of the request object, the corresponding Bean property will not set any value. Similarly, if there is a property in Bean that does not have a corresponding Request parameter value, then this property will not be set either.
Property= "propertyName" [param= "parameterName"]
Use a parameter value in request to specify a property value in Bean. In this syntax, property specifies the property name of Bean, and param specifies the parameter name in request.
If the name of the bean attribute is different from that of the request parameter, then you must specify property and param. If they have the same name, you only need to specify property.
If the lookup parameter value is empty (or uninitialized), the corresponding Bean property is not set.
Property= "propertyName" value= "{string /}"
Sets the Bean property using the specified value. This value can be a string or an expression. If this string, then it will be converted to the type of Bean property (see the table above). If it is an expression, then its type must be the same as the type of attribute value it is going to set.
If the parameter value is empty, the corresponding property value will not be set. In addition, you can't use both param and value in one
Sports Acrobatics
If you use property= "*", then the properties of Bean do not need to be sorted in the order in the Html form
=
Create an instance of Bean and specify its name and scope.
JSP syntax
/
> other elements
}
Examples
Description
Used to locate or sample a JavaBeans component. First, an attempt is made to locate an Bean instance, and if the Bean does not exist, the example is taken from a class or template.
In order to locate or exemplify a Bean, the following steps are aggregated in the following order:
Try to locate a Bean with a given name and range.
The reference variable to this Bean object is named after the name you specify.
If the Bean is found, the reference will be stored in the variable. If you also specify a type, then the Bean is also set to the corresponding type.
If the Bean is not found, the example will be taken from the class you specified and the reference will be stored in a new variable. If the name of the class represents a template, then the Bean is java.beans.Beans.instantiate example.
If you have already exemplified (not located) the Bean and have elements in it, the code in it will be executed.
The body of an element usually contains an element that sets the attribute value of the Bean. As mentioned in step 5 above, the subject will only be executed in the example Bean. If the Bean already exists and can be located, then the content in the subject will not work.
Attribute and usage
Id= "beanInstanceName"
Confirm the Bean variable in the scope you define, and you can use this variable name later in the program to distinguish between different Bean
This variable name is case-sensitive and must conform to the rules of the scripting language you are using, which is stated in the Java Language specification in Java Programming Language. If the Bean has been created in something else, the value of the id must be the same as the original id value.
Scope= "page / request / session / application"
The scope of the existence of Bean and the valid range of id variable names. The default value is page, and here is a detailed description:
Page-you can use Bean in the JSP file that contains elements and all static include files in this file until the page is executed and the response is sent back to the client or transferred to another file.
Request-you use Bean in any Jsp file that executes the same request until the page finishes sending back a response to the client or transferring to another file. You can use Request objects to access Bean, such as request.getAttribute (beanInstanceName)
Session-from the beginning of creating Bean, you can use Bean. Bean in any Jsp file that uses the same session. This Bean exists throughout the Session life cycle, and any Jsp file that shares this Session can use the same Bean. Note that session=true must be specified in the instructions in the Jsp file where you create Bean
Application-from the beginning of creating Bean, you can use Bean. Bean in any Jsp file that uses the same application. This Bean exists throughout the application life cycle, and any Jsp file that shares this application can use the same Bean.
Class= "package.class"
Use the new keyword and the class constructor to sample a bean from a class. This class cannot be abstract and must have a common, parameter-free constructor. The name of this package is case-sensitive.
Type= "package.class"
If the Bean already exists in the specified scope, write the Bean to a new database type. If you do not use class or beanName to specify type,Bean, it will not be example .package and class names, case sensitive.
BeanName= "{package.class /}" type= "package.class"
Use the java.beans.Beans.instantiate method to sample a Bean from a class or continuous template, while specifying the type of Bean.
BeanName can be package and class or an expression, and its value will be passed to Beans.instantiate.tupe with the same value as Bean.
Package and class names are case sensitive. The above is all the content of this article "sample Analysis of JSP Grammar". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.