Use of C tag in JSP __js

Source: Internet
Author: User
Tags error handling
use of C tags in jsp

Core Tag Library

It is the core library in Jstl, providing common support for day-to-day tasks, such as displaying and setting variables, reusing a set of projects, testing conditions, and other actions such as importing and redirecting Web content. Core labels can be divided into 4 types by function:

1 Variable Maintenance:

(1) <c:set&gt: Set Variable values and object properties. The syntax is as follows:

<c:set value= "value var=" variable name "scope=" variable's scope "target=" Object name property= "object property name" ></c:set>

Each setting has two ways to sum up the 4 forms of,<c:set>, as follows:

A. Setting a JSP variable with a tag property

<c:set value= "value" var= "variable name" scope= "Scope"/>

B. Setting a JSP variable with a tag body

<c:set var= "variable name" scope= "Scope" > tag content </c:set>

C. Setting object properties with Tag properties

<c:set value= "variable name" target= "Object Name" property= "object property name"/>

D. Setting object properties with a tag body

<c:set target= "Object name" property= "Scope" > tag content </set>

(2) <c:remove&gt: Deletes a variable within the specified scope. The syntax is as follows:

<c:remove var= "variable name" scope= "Scope"/>

2 Process Control: It is divided into conditional label and iterative label.

Conditional label:<c:if> <c:choose> <c:when> <c:otherwise>

(1) <c:if&gt: Similar to the use of IF statements in the Java language, but cannot implement else functions.

The <c:if> label has two grammatical forms, which are distinguished by the use of unmarked bodies.

No label body:

<c:if test= "test condition" var= "variable name" [scope= scope]/>

Has the label body:

<c:if test= "test condition" var= "variable name" [scope= scope]>

Label body

</c:if>

<c:if> with tagged body

<c:if test= "${user.visitcount!=0}" > Welcome </c:if>

(2) <c:choose> <c:when> <c:otherwise>

<c:when> <c:otherwise> cannot be used alone and can only be used as a child label for <c:choose>. These three tags combine to implement the functionality of the switch statements in Java. The syntax is as follows:

<c:choose>

<c:when test= "${user.class== ' guest '}" >

Label Body 1

</c:when>

<c:when test= "${user.class== ' VIP '}" >

Label Body 2

</c:when>

<c:otherwise>

Label Body 3

</c:otherwise>

</c:choose>

Iterative label:<c:foreach> <c:forTokens>

(1) <c:foreach&gt: Used to traverse a collection of objects.

<c:foreach var= "variable name" items= "collection" varstatus= "Traversal state name"

begin= "Begin" end= "End" step= "Step" >

Label body

</c:forEach>

(2) <c:fortokens&gt: Used to traverse a string, and each traversal result returns a word in the string.

<c:fortokens items= "string" delims= "delimiter" var= "variable name"

varstatus= "Traverse state name" begin= "Begin" end= "End" step= "Sep" >

Label body

</c:forTokens>

3 URL Management

(1) <c:url&gt: Used to encode URL addresses.

Has the label body:

<c:url value= "url" context= "path" var= "variable name" scope= "Scope" >

Label body

</c:url>

The following code:

<c:url value= "http://localhost:8080/el/index.jsp" var= "Newurl" >

<c:param name= "name" value= "zero"/>

<c:param name= "age" value= "/>"

</c:url>

<a href= "${newurl}" > Dot me </a>

Generated url:http://localhost:8080/el/index.jsp?name=zero&age=28

No label body: used primarily for editing context URLs.

<c:url value= "url" context= "path" var= "variable name" scope= "Scope"/>

The following code:

<c:url value= "/logon.jsp" > Login </c:url>

If the current path is El, the output is:/el/logon.jsp

(2) <c:import&gt: Introduce URL resources to the current JSP page (can be resources on a remote program site). Include directives and include actions cannot introduce resources other than web programs to JSP pages, and the resources introduced must be in the current Web program.

Syntax introduced as a string object:

<c:import url= "Address" context= "Context path" var= "variable name"

Scope= "Scope" charencoding= "character Set" >

Label body using <c:param>

</c:import>

The following code: introducing external resources into the current JSP page.

<c:import url= "http://www.hao123.com" var= "Myurl" charencoding= "gb2312" >

</c:import>

<a href= "${myurl}" > Address </a>

Syntax imported as a Reader object:

<c:import url= "Address" context= "Context path" varreader= "variable name"

Scope= "Scope" charencoding= "character Set" >

The label body uses other action elements

</c:import>

(3) <c:redirect&gt: for HTTP redirection.

No label body:
<c:redirect url= "Address" context= "Context path"/>

Has the label body:

<c:redirect url= "Address" context= "Context path" >
<c:param/> Label
</c:redirect>

(4) <c:param&gt: can only be used as a child element in <c:url>, <c:import>, <c:redirect> tags. This label is primarily used to set the parameters that will be passed in the URL.

No label body:

<c:param name= "name" value= "value"/>

Has the label body:

<c:param name= "name" value= "Value" >
Label body
</c:param>

4 other labels:<c:out>, <c:catch>.

(1) <c:out&gt: Display variable contents in JSP page.

No label body:

<c:out value= "value" escapexml= "{true|false}" default= "Default value"/>

Has the label body:

<c:out value= "value" escapexml= "{true|false}" default= "Default Value" >
Label body
</c:out>

which

Default: Specifies the value that should be output when value is null.

EscapeXML: Used to set whether to escape "<", ">", "&", "" "," "," "," and "".

The EscapeXML defaults to true to indicate that the conversion occurred.

"<" converted to "&lt"

">" Converted to "&gt"

"&" converted to "&amp"

"'" Converted to "& #039"

"" To "& #034"

(2) <c:catch&gt: For handling JSP page errors.

If there is an error in the JSP page, you can go to the error-handling page by setting the page directive property. <c:catch> tags are a complement to this error handling. It is handled by embedding a snippet of JSP code that might have an exception in the tag body, and then using the Var property to receive the exception thrown by the tag body.

<c:catch var= "variable name" >
Nested actions
</c:catch>

How to use:

<c:catch var= "MyException" >
Nested actions
</c:catch>

<c:if test= "${myexception!=null}" >
Content
</c:if>

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.