7 directives in the JSP

Source: Internet
Author: User
Tags processing instruction

The action instruction differs from the compilation instruction by informing the servlet engine of the processing of the message while the action instruction is just the run-time action.

The compile instruction works when the JSP is compiled into a servlet, and the processing instruction is usually replaced with a JSP script, which is just a standardized notation for JSP scripts.

(1) JSP:forward performs a page turn and forwards the processing of the request to the next page.

(2) JSP:param is used to pass parameters and must be used with other labels that support parameters

(3) JSP:include for dynamically introducing a JSP page

(4) JSP:plugin for downloading JavaBean or applets to client execution

(5) JSP:usebean Create a JavaBean instance

(6) JSP:setProperty Setting property values for JavaBean instances

(7) JSP:getProperty Gets the property value of the JavaBean instance

A forward Directive
Used to forward a page to another page, either forward to a static HTML page, or forward to a dynamic JSP page, or to a servlet in a container.

Dynamic instruction only needs direct <> instruction, Static is <%%&gt, and dynamic instruction is in pairs.
The forward instruction format for JSP is as follows:
For the JSP1.0 syntax: <jsp:forward page= "{relativeurl|<%=expression%>}"/>
For JSP1.1 above specification, the syntax is: <jsp:forward page= "{relativeurl|<%=expression%>}" >
{<jsp:param />}
This syntax is used to add additional request parameters when forwarding. The value of the increased request parameter can be obtained through the GetParameter () method of the HttpServletRequest class. When executing the forward instruction, the address requested by the user remains unchanged and is still a request, but the content of the page is completely changed to the content of the forward target page. The client's request parameters are not lost when executing the forward instruction forwarding request.

Twoinclude Directives
Include directive when a dynamic include directive is also used to contain a page, it does not import the compilation instructions of the Include page, only the body content of the imported page is inserted into the page.
<jsp:include page= "{relativeurl|<%=expression%>}" flush= "true" >
<jsp:param name= "parametername" value= "ParameterValue"/>
The Flush property is used to specify whether the output cache is transferred to the file being imported, if true, to be included in the file being imported, or to be included in the original file if False is specified. For JSP1.1 older versions, only set to false.
Note: include static: Compile instructions-----Two JSP pages fused into a servlet
Include dynamic: Action directives------using include in Servlets to introduce the content of imported pages
The static Import page must be the same as the compilation instruction of the imported page, otherwise it will go wrong and the dynamic will contain only the body part.
Threeuserbean,setproperty,getproperty Directive
These three instructions are javabean-related directives, where the userbean instruction Initializes a Java instance in the JSP page, setproperty instruction is used to set the value of the JavaBean instance's properties The GetProperty directive is used to output the properties of an JavaBean instance.

If multiple JSP pages need to be reused in a piece of code, we can define this code as a Java class method, and then multiple JSP pages call the method, which can achieve good code reuse.

The syntax format for Userbean is as follows
<jsp:userBean id= "name" class= "classname" scope= "Page|request|session|application"/>
Where the id attribute is the instance name of JavaBean, the class property determines the implementation class of the JavaBean. The scope property is used to specify the scope of the JavaBean instance.

SetPropertyThe syntax format
<jsp:setproperty name= "Beanname" property= "PropertyName" value= "PropertyValue"/>

Where the Name property is to determine the instance name of the JavaBean,Property attribute to determine the attribute name of the setting propertyThe Value property to be determined when the property name corresponds.

Syntax format for GetProperty

<jsp:getproperty name= "Beanname" name= "PropertyName"/>

Where the Name property is to determine the instance name of the JavaBean, the Name property is the value that specifies the property name to get.

Note: When using the Userbean tag, in addition to creating the JavaBean instance in the page script, the label also puts the JavaBean instance into the specified scope, so we also need to put JavaBean into the specified scope in the script, as shown in the following code:

Pagecontext.setattribute ("Beanname", Beanname)

Request.setatttibutr ("Beanname", Beanname)

Session.setattribute ("Beanname", Beanname)

Application.setattribute ("Beanname", Beanname)

Fourplugin Directive

The plugin instruction is primarily used to download server-side JavaBean or applets to client execution, because the program executes on the client, so the client must install the virtual machine.

Fiveparam Directive

The param is used to set the parameter value, and the instruction itself cannot be used alone, so a separate param instruction does not make sense, and the Param directive can be used in conjunction with the following instruction


7 directives in the JSP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.