Monday, July 26, 2010

Some knowledge of JSP syntax



1.JSP instructions

Use JSP directives (including) to specify a scripting language used, Servlet implementation interface, Servlet extension classes, Servlet import packages. The general command syntax of JSP form:. One effective instruction, called:

(1) language: documents used in the scripting language. At this point the Java programming language, Java is only valid values and default values. The Directive on the whole document. When the repeated use of the instruction, only the first time to be effective. Examples are as follows:.

(2) Method: from the embedded Java code (scriptlet) generated method name. Generated code will be designated the main method name. The default is service. When the repeated use of the instruction, only the first time to be effective. Examples are as follows:.

(3) Import: Servlet into the Java language package name or class name list, the list is separated by commas. In the JSP file, you can specify the command to import many different packages. Examples are as follows:.

(4) content_type: MIME type of response generated. The default value is text / html. When the repeated use of the instruction, only the first time to be effective. The directive can be used to specify the page in which the character set encoding. Examples are as follows:.

(5) mplements: Servlet implementation used to generate a list of Java language interfaces, the list is separated by commas. In a JSP file using the command several times to achieve different interfaces. Examples are as follows:.

(6) extends: Servlet extended Java language class name. Class must be effective, and can not be a Servlet class. The directive effect on the entire JSP file. When the repeated use of the instruction, only the first time to be effective. Examples are as follows:.

2.class-wide variables and methods

Use

Markers to illustrate Servlet class class-wide variables and class-wide approach. General syntax is as follows:




Attribute runat = server is required, it indicates that the tag is used for server-side processing. Specified class-wide variables and methods example are as follows:




3. Access JavaBean

JavaBean JSP syntax support enables you to reuse components through the Web site. JavaBean class file or can be serialized Bean, Servlet may also be dynamically generated. Please use the tags to create a Bean instance, to make the JSP file from anywhere can access the instance. Tag syntax is:



One of the attributes and their meanings are as follows:

(1) name: for in the appropriate range (specified by the scope attribute) within the look Bean's name. For example, this may be used to store Bean's session (session) key value. The value is case-sensitive.

(2) varname: JSP file is used in reference Bean name anywhere. This property is optional. The default value name attribute value. The value is case-sensitive.

(3) type: Bean class file name. The code name used to description Bean instance. The default value of Object type. The value is case-sensitive.

(4) Introspect: When the value is true, JSP processor checks all the request attributes, and call and request attributes set attribute method of matching sets (the property is passed in the BeanInfo). The default value of the property is.

(5) BeanName: Bean's. Class file name, Bean Bean package name or contains the serial of file (. Ser file) of the file name. (The name is an instance of the program to the Bean). Only when the Bean is not specified range, and attribute is set to be created only when the use of the property. The value is case-sensitive. File path to the Java application server class path specified, unless the file applicationserver_rootservlets directory.

(6) Create: When the value is true, if the processor is not found within the specified Bean, the JSP will create a Bean instance. The default value is true.

(7) Scope: Bean's life cycle. This property is optional, its default value is request. Valid values are:

request - the Servlet request to Bean set the context, the use of the Servlet API JSP API is described in notes

With the JSP file. If the Bean is not part of the request context, it will create the Bean, and stores it in the context of the request, unless the create attribute is set to No.

session - if the current dialogue exists Bean, the Bean has been reused. If there is no Bean, and create a property set

Is yes, then it has been created and stored as part of the session.

userprofile - retrieval by the Servlet request object, shape into the specified type, and for introspection user Jian Yaobiao file. (In

IBM WebShere application server, the default type com.ibm.servlet.personalization.userprofile.UserProfile).

(8) param: list of attributes and value pairs. Bean property is automatically set using introspection. Bean instantiated only when in the best attribute set.

In addition to using attributes to set Bean properties, but also can use the other three methods: first, the request contains the Bean's Web page (JSP file) of the URL, specify the query parameters. Must be introspective property set to "yes." The examples are as follows: http://www.myserver.com/signon.jsp?name=jones&password=d13x, Bean property which is set to star jones. The second method, the property designated as submitted by the HTML tag parameters. Mothod property must be set to post. The action attribute set to call the JSP Bean file URL. Introspect attribute must be set to "yes." The examples are as follows:




The third method is to use the JSP syntax to set Bean properties.

In the specified tag, you can anywhere in the JSP file to access Bean. There are three ways to access Bean properties: use JSP scriptlet, JSP expression is used, use the tag (as variable data, HTML template syntax described). Please refer to the JSP example (DisplayData.jsp file) to get the three access methods for each method the sample Bean.

4. Directly into the Java code (scriptlet)

JSP documents can be directly embedded into any valid markers of Java language code. This embedded code is called scriptlet. If no method directive, the generated code will be the main service methods. The scriptlet for Servlet can use a predefined set of variables, the set of variables consistent with the basic Servlet, output and input categories:

(1) request: a request by the javax.servlet.http.HttpServletRequest class defines the Servlet

(2) responses: Servlet response defined by the javax.servlet.http.HttpServletRequest class

(3) out: the definition of the output from the java.io.PrintWriter class transcription program

(4) in: defined by the java.io.BufferedReader input reader class

The examples are as follows:



5. Variable data, HTML template syntax

When the page is returned to the browser, application server, HTML template syntax so you can put HTML page variable field, and to Servlet and JavaBean can be used to replace the database the value of the dynamic variables. This feature is an IBM extension JSP, it makes reference to the variable data becomes very easy. The syntax is only for JSP files. HTML template syntax, including:

Basic HTML template syntax;

Alternative HTML template syntax;

Tag.

These tags by HTML authoring tools are designed to deliver interoperability mark. Each tag has a corresponding end tag. Each tag is case-sensitive, some of their properties are case-sensitive. IBM WebSphere Studio allows developers to JSP file to include the HTML template syntax easier.

(1) basic HTML template syntax

Tag is used to specify variable field of the basic mark. General syntax is:



One of the attributes and their meanings are as follows:

requestparm: To request a visit within the parameters of the object. The property is sub-case, and can not be used with Bean and property attributes.

Requestattr: To request a visit to the property within the object. Property should be set using setAttribute method. The property is sub-case, and can not be used with Bean and property attributes.

Bean: the marker described in the JavaBean JSP file name. Please refer to the JavaBean to get the tags to access the explanation. The attribute value is case-sensitive. When the specified Bean property, but did not specify the property attribute, will be used in replacement of the complete Bean. For example, if a type of String Bean and did not specify the property value string will be replaced.

Property: Access replacement Bean property. The value of the property is sub-case, and is the property of the independent site name. The property can not be used in conjunction with the requestparm property.

Default: When the Bean attribute value is empty, display an optional string. If the string contains multiple words, then the string must be included in a pair of double quotes (eg "HelpDesk number"). The attribute value is case-sensitive. If you do not specify a value, then when the property value is empty, replace with an empty string.

Examples of the basic JSP syntax is as follows:



In most cases, property value of the property is the property name. However, you can specify the property attribute to access the properties of the whole format of a property (a property). The whole format is also available to you to select items of a specified index property index. The optional index can be a constant (for example 2) or set the HTML tags as described in the repeated index. All formats use the property tag example is as follows:



(2) to replace HTML template syntax

HTML standard does not allow HTML tags embedded in HTML tags. Thus, HTML tags can not be embedded in another tag. Instead, please use the alternative HTML template syntax. To use the alternative syntax:

Please use and to include HTML tags in the tag that alternative content.

Bean and property attributes specified:

Bean and attributes to specify features, please use the following format: $ (bean = b property = p default = d), where b, p and d

As described in the value of basic grammar.

To specify requestparm property, please use the following format: $ (requestparm = r default = d), where r and d as

Describe the basic syntax of the value.

To specify requestattr property, please use the following format: $ (requestattr = r default = d), where r and d, as described

The value of the basic JSP syntax.

Alternative HTML template syntax examples are as follows:

Show map of city

(3) mark

Tag syntax is:



Of which:

index: is used to identify the duplicate data block an optional name. The value is case-sensitive.

Start: duplicate data blocks for the start of an optional index value. The default value is 0.

End: duplicate data block for the end of an optional index value. Maximum value is 2,147,483,647. If the end of the property value of the property value is less than the beginning, the end attribute is ignored.

The following examples 1,2 and 3 show how to use the mark. If all of the index properties have 300 or fewer elements, these examples will produce the same output. If you have more than 300 elements, Example 1 and Example 2 will show all the elements, while Example 3 will only show the first 300 elements. Example 1 with the default start and end of the index shows the implicit index: using the minimum number of bean indexed properties restricts the number of cycle to repeat.





Example 2 shows the index, starting index and ending index:


Example 3 starting with the implicit explicit index shows the index and end index. Although the index attribute is specified, the index still had the property of the city on the implicit index, because without (i).





Data blocks can be nested. Separate index for each block of data. The ability to cross the staggered two bean properties or properties with sub-attributes is very useful. In the example, the two data blocks nested, to show the user shopping cart with a compressed disc of each song list.






6. Variable data Java expression

When dealing with JSP files, to specify the decomposition of a Java language expression, use the JSP expression tags. The expression is evaluated and converted into a string, and display them. Primitive types such as int and float are automatically converted to string representation. In this example, foo is



Translation Welcome.

When access to JSP files, text: Translation Welcome Hello.

Some knowledge of the JSP syntax introduced here.









Recommended links:



Mars text input text input V2.7.2 version of EASY Fun



Baidu Key words after switching price inflation Phoenix Nest 8 times



Facebook registration. Cn DOMAIN name eagerly want to move into China



Ramada Pearl Hotel



Tencent in 2007, Beijing ad: tech conference on the show "Tencent MIND



Wizard Religion



how to convert Flv to 3gp



Convert flv to 3gp



Tyson Foods to ELIMINATE non-value-added production processes



avi to ipod TOUCH



Games Simulation Infomation



Photoshop To Create Beauty Facial Skin Texture



Terminal And Telnet Clients introduction



REVIEW Password Managers



Convert Mkv To Avi Free



No comments:

Post a Comment