The action commands are different from the compilation commands. The compilation commands notify the servlet engine to process messages, while the action commands are only script actions during running. The compilation command works when compiling JSP into servlet: The processing command can usually be replaced with a Java Script, which is a standardized way of writing JSP scripts.
Jsp7 action commands are as follows:
JSP: Forward: executes the page redirection and forwards the request processing to the next page.
JSP: Param: used to pass parameters. It must be used with other supported parameter Qu tags.
JSP: include: Used to dynamically introduce a JSP page.
JSP: Plugin: used to download JavaBean or applet to the client for execution.
JSP: usebean: Use Javabean.
JSP: setproperty: Modify the attribute value of a JavaBean instance.
JSP: getproperty: gets the attribute value of the JavaBean instance.
1. Forward Command
The forward command is used to forward the page response to another page. It can be forwarded to static html pages, dynamic JSP pages, or servlet in the container.
The format of the JSP Forward Command is as follows.
For JSP 1.0, use the following syntax:
<JSP: Forward page = "{relativeurl | <% = expression % >}"/>
For JSP 1.1 or later, you can use the following syntax:
<JSP: Forward page = "{relativeurl | <% = expression % >}">
{<JSP: Param.../>}
</Jsp: Forward>
The second syntax is used to add additional request parameters when forwarding. The added request parameter value can be obtained through the getparameter () method of the httpservletrequest class.
The following example uses the forward action command to forward user requests.
<JSP: Forward page = "forward-result.jsp">
<JSP: Param name = "Age" value = "29"/>
</Jsp: Forward>
The client request is forwarded to the forward-result.jsp page with a request parameter named age and a value of 29 added to the request.
On the forward-result.jsp page, use the request built-in object (the request built-in object is an instance of httpservletrequest) to get the added request parameter value.
<! -- Use the built-in request object to obtain the value of the age parameter -->
<% = Request. getparameter ("Age") %>
When the forward request is executed, the client's request parameters are not lost.
When the Forward Command is executed to forward the request, the address of the user request is not changed, but the page content is completely changed to the content on the target page of the forward.
2. include command
The include command is a dynamic include command, which is also used to import a page. It does not import the compilation instructions of the include page, but simply inserts the body content of the imported page into this page.
The syntax format of the include Action Command is as follows:
<JSP: Include page = "{relativeurl │ <% = expression %>}" Flush = "true"/>
Or
<JSP: Include page = "{relativeurl │ <% = expression %>}" Flush = "true">
<JSP: Param name = "parametername" value = "patametervalue"/>
</Jsp: Include>
The flush attribute is used to specify whether the output cache is transferred to the imported file. If it is set to true, it is included in the imported file; if it is set to false, it is included in the original file. For earlier versions of JSP 1.1, it can only be set to false.
For the second syntax format, you can add additional request parameters to the imported page.
The following page uses the dynamic import syntax to import the specified JSP page.
<! -- Use the dynamic include command to import the page -->
<JSP: Include page = "scriptlet. jsp"/>
Bold characters on the above pageCodeThe dynamic import syntax is used to import scriptlet. jsp. On the surface, the execution result of the page is no different from that of the page imported using static include. But view the jsp-include.jsp page to generate the Servlet'sSource code, You can see the following snippet:
// Use the page output stream to generate HTML Tag content
Out. Write ("<! Doctype HTML public/"-// W3C // dtd html 4.0 transitional // en/">/R/N ");
Out. Write ("<HTML>/R/N ");
Out. Write ("
Out. Write ("<title> JSP-include test </title>/R/N ");
Out. Write ("
Out. Write ("<body>/R/N ");
// Dynamic import, Directly introducing the scriptlet. jsp page
Org. Apache. Jasper. runtime. jspruntimelibrary. Include (request, response,
"Scriptlet. jsp", out );
Out. Write ("/R/N ");
Out. Write ("</body>/R/N ");
Out. Write ("
Out. Write ("/R/N ");
The bold text code in the above code snippet shows the key to dynamic import: dynamic import only uses an include method to insert the content of the target page, rather than fully integrating the target page into this page.
To sum up, there are two differences between static and dynamic imports:
Static import fully integrates the code of the imported page and the two pages into a servlet. Dynamic import uses the include method in the servlet to introduce the content of the imported page.
During static import, the compilation commands on the imported page take effect. during dynamic import, the compilation commands on the imported page become useless, but only the body content of the imported page is inserted.
In addition, additional request parameters can be added when the include dynamic command is executed.
The bold characters in the preceding JSP page also use the JSP: include command to import the page, and the JSP: include command also uses the param command to input parameters, this parameter can be obtained using the request object on the forward-result.jsp page.
3. usebean command
<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 ".
4. 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"
6. 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.
7. Param commands
The param command is used to set the parameter value. This command cannot be used independently. A separate Param command has no practical significance. The param command can be used with the following three commands:
JSP: Include
JSP: Forward
JSP: plugin
The syntax format of the param command is as follows: