JSP syntax (2) (1)

Source: Internet
Author: User

JSP syntax

<jsp:forward page={"relativeURL" / "<%= expression %>"} />or <jsp:forward page={"relativeURL" / "<%= expression %>"} >
<jsp:param name="parameterName" value="{parameterValue / <%= expression %>}" />+ </jsp:forward>

Example

<jsp:forward page="/servlet/login" /> <jsp:forward page="/servlet/login"> <jsp:param name="username" value="jsmith" /> </jsp:forward> 

Description

The tag transmits a request object containing user requests from one JSP file to another. The following code cannot be executed.

You can send parameters and values to the target file. In this example, the parameter name is username and the value is scott. If you use Tag, the target file must be a dynamic file that can process parameters.

If you use non-buffered output, use Always Be careful. If you use Previously, the jsp file has data, so the File Execution will fail.

Attribute

Page = "{relativeURL/<% = expression %> }"

Here is an expression or a string used to indicate the file or URL you want to target. this file can be JSP, program segment, or other files (such as asp, cgi, php) that can process request objects ).

+

Send one or more parameters to a dynamic file. This file must be a dynamic file.

If you want to pass multiple parameters, you can use multiple . Name specifies the parameter name and value specifies the parameter value.


Obtains the Bean property value, which is displayed on the page.

JSP syntax

<jsp:getProperty name="beanInstanceName" 
property="propertyName" /> 

Example

<jsp:useBean id="calendar" scope="page" 
class="employee.Calendar" />
<h2>Calendar of <jsp:getProperty name="calendar" 
property="username" /></h2>

Description

This The element obtains the Bean property value and can be used or displayed on the JSP page. Before, you must use Create it.

Elements have some limitations:

You cannot use To retrieve an indexed attribute.
You can use it with the JavaBeans component But cannot be used with Enterprise Bean.

Attribute

Name = "beanInstanceName"

Bean name Specify

Property = "propertyName"

Attribute name of the specified Bean.

TIPS:

As mentioned in sun's JSP reference, if you use If the value to be retrieved is null, then NullPointerException will occur. If the program segment or expression is used to retrieve the value, null is null in the browser ).


Contains a static or dynamic file.

JSP syntax

<jsp:include page="{relativeURL / <%= expression%>}" flush="true" /> or <jsp:include page="{relativeURL / <%= expression %>}" flush="true" > <jsp:param name="parameterName" value="{parameterValue / 
<%= expression %>}" />+ </jsp:include>

Example

<jsp:include page="scripts/login.jsp" /> <jsp:include page="copyright.html" /> <jsp:include page="/index.html" /> <jsp:include page="scripts/login.jsp"> <jsp:param name="username" value="jsmith" /> </jsp:include> 

Description

Element allows you to include dynamic files and static files. The results of these two types of files are different. If the file is only a static file, this inclusion only adds the content of the contained file to the jsp file. If the file is dynamic, the included file will be executed by the Jsp compiler (similar to asp)

You cannot determine whether a file is dynamic or static from the file name. For example, aspcn. asp may only contain some information, but does not need to be executed. These two types of files can be processed at the same time. Therefore, you do not need to determine whether the file is dynamic or static.

If the file is dynamic, you can use The parameter names and values are also passed.

Attribute

Page = "{relativeURL/<% = expression %> }"

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. The default value is false.

+

The clause allows you to pass one or more parameters to a dynamic file.

You can use multiple To pass multiple parameters.


Related Article

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.