The JSP page consists of the following elements: l static content. The static content is the static text in the JSP page. It is basically HTML text and has nothing to do with Java and JSP syntax. L command. JSP commands generally use "<% @ attribute = Value %> ". L expression. The JSP expression ends with "<% = expression %>. L scriptlet. Scriptlet is a piece of Java code embedded in the page, with "<% Java code %> ". L statement. JSP declarations are used to define variables and methods on the JSP page. It starts with "<%! Variable and method %> ". L action. JSP actions allow control to be transferred between pages. The syntax is "<JSP: Action Name property = value/>" or "<JSP: Action Name property = value> body </jsp: Action Name> ". L annotation. There are two types of Annotations: "<! -For this annotation client, you can see --> "," <% -- %> ". Use of JSP scripts and commands
L JSP script elements include declarations, scriptlet, and expressions.
L JSP expressions are used to calculate the expression value and written in the form of <% = code %>. JSP declaration is used to declare variables and methods, and with <%! Code %>. Jspscriptlet is used to insert complex Java code into the JSP page and write it in the form of <% code %>.
There are three types of commands: Page, include, and taglib. All commands are included in the <% @ %> label.
L The page command is used to set attributes of JSP pages. The include command is used to embed files into JSP pages. The taglib command allows users to use custom tags.
Action commands in JSP include, forward, usebean, getproperty, setproperty, and plugin.
I. include commands
<JSP: Include> the tag indicates a static or dynamic file.
Syntax:
<JSP: Include page = "path" Flush = "true"/>
Or
<JSP: Include page = "path" Flush = "true">
<JSP: Param name = "paramname" value = "paramvalue"/>
</Jsp: Include>
Note:
1. Page = "path" is a relative path or a relative path expression.
2. Flush = "true" must be set to true. The default value is false.
3. The <JSP: param> clause allows you to pass one or more parameters to a dynamic file. You can also use multiple <JSP: param> to pass multiple parameters to a dynamic file.
Ii. Forward Command
<JSP: Forward> the tag indicates redirecting a static html/JSP file or a program segment.
Syntax:
<JSP: Forward page = "path"}/>
Or
<JSP: Forward page = "path"}>
<JSP: Param name = "paramname" value = "paramvalue"/> ......
</Jsp: Forward>
Note:
1. Page = "path" is an expression or a string.
2. <JSP: param> name specifies the parameter name and value specifies the parameter value. The parameter is sent to a dynamic file. The parameter can be one or more values, but the file must be a dynamic file. To pass multiple parameters, you can use multiple <JSP: param> In a JSP file to send multiple parameters to a dynamic file.
Iii. usebean instructions
<JSP: usebean> A tag is used to create a bean instance on the JSP page and specify its name and scope.
Syntax:
<JSP: usebean id = "name" Scope = "Page | request | session | application" typespec/>
Typespec has the following possibilities:
Class = "classname" | class = "classname" type = "typename" | beanname = "beanname" type = "typename" | type = "typename" |
Note:
You must use class or type instead of both Class and beanname. Beanname indicates the bean name in the form of "A. B. C ".
Iv. getproperty command
<JSP: getproperty> the tag is used to obtain the bean property value, convert it into a string, and insert it into the output page.
Syntax:
<JSP: getproperty name = "name" property = "propertyname"/>
Note:
1. Before using <JSP: getproperty>, you must use <JSP: usebean> to create it.
2. You cannot use <JSP: getproperty> to retrieve an indexed property.
3. It can be used with the JavaBeans component <JSP: getproperty>, but cannot be used with Enterprise Java Bean.
5. setproperty command
<JSP: setproperty> tag indicates the attribute value in bean.
Syntax:
<JSP: setproperty name = "beanname" prop_expr/>
Among them, prop_expr has the following possible situations:
Property = "*" | property = "propertyname" | property = "propertyname" Param = "parametername" | property = "propertyname" value = "propertyvalue"
Note:
Use JSP: setproperty to assign values to the attributes of a bean. You can use either of the following methods.
1. Use JSP: setproperty: After JSP: usebean:
<JSP: usebean id = "myuser "... />
...
<JSP: setproperty name = "user" property = "user "... />
In this way, JSP: setproperty will be executed.
2. jsp: setproperty appears in the JSP: usebean Tag:
<JSP: usebean id = "myuser "... >
...
<JSP: setproperty name = "user" property = "user "... />
</Jsp: usebean>
In this way, JSP: setproperty is executed only when a new object is instantiated.
* The name value in <JSP: setproperty> should be the same as the id value in <JSP: usebean>.
Vi. plugin commands
<JSP: plugin> the tag indicates executing an applet or bean. If possible, you need to download a Java Plug-in to execute it.
Syntax:
<JSP: plugin
Type = "bean | applet"
Code = "classfilename"
Codebase = "classfiledirectoryname"
[Name = "instancename"]
[Archive = "uritoarchive,..."]
[Align = "bottom | top | Middle | left | right"]
[Height = "displaypixels"]
[Width = "displaypixels"]
[Hspace = "leftrightpixels"]
[Vspace = "topbottompixels"]
[Jreversion = "Maid number | 1.1"]
[Nspluginurl = "urltoplugin"]
[Iepluginurl = "urltoplugin"]>
[<JSP: Params>
[<JSP: Param name = "parametername" value = "{parametervalue | <% = expression %>}"/>] +
</Jsp: Params>]
[<JSP: fallback> text message for user </jsp: fallback>]
</Jsp: plugin>
Note:
<JSP: plugin> elements are used to play or display an object (typically an applet and bean) in a browser, and such display needs to be implemented in the browser's Java Plug-in.
When the JSP file is compiled and sent to the browser, the <JSP: plugin> element will be replaced with the <Object> or <embed> element based on the browser version. Note: <Object> is used for HTML 4.0 and <embed> is used for HTML 3.2.
In general, the <JSP: plugin> element specifies whether the object is an applet or bean, the class name, location, and where to download the Java Plug-in.
About JavaBean
JavaBean should have the following requirements:
L Javabean is a Java public class.
L has the default constructor.
L The first letter of the attribute is lowercase.
L there are get and set methods.
JSP actions: Action 1
<JSP: usebean id = "beanname class =" beanclass "scope =" page/session/application/request "/>
Where:
ID is used to create a reference name for the bean.
Class specifies the Bean class, full name: "package. Class ".
Scope specifies the bean range. By default, scope is set to page.