Java Web Learning (+): Jstl Learning (iii)

Source: Internet
Author: User

Common Core tags introduction

Jstl has a total of 13 core tags, functionally divided into 4 categories:

1) Expression Control label

<c:out>, <c:set>, <c:remove>, <c:catch>

2) Process Control label

<c:if>, <c:choose>, <c:when>, <c:otherwise>   

3) Cycle label

<c:forEach>, <c:forTokens>

4) URL Action tag

<c:import>, <c:url>, <c:redirect>
<c:out> sign

<c:out> tags are the result of displaying expressions, similar in the way <%=%> effect, with their different <c:out> tags can be used simple "." Exercise

Character to access the property. For example, to access Customer.address.street, the tags used are:

<c:out value= "Customer.address.street"/>

The <c:out> tag automatically escapes the XML tags so that they are not counted as actual tags.

The <c:out> tag has the following properties:

Usage of <c:out> Tags:

1) Output constants: can be assigned directly in the attribute value

2) Output variable: When a variable does not exist, it can be used to output the default value with the Defalut property, and the output of the escape character can also be controlled through the property EscapeXML

Expression

Instance:

Results:

<c:set> Tags

The <c:set> tag is a friendly version of Jstl's SetProperty action. The label is useful because its expression evaluates and uses the result of the

Sets a value for the JavaBean or Java.util.Map object.

The <c:set> tag has the following properties:

If you specify a target, the attribute must also be specified.

Usage of <c:set> Tags:

1) stored value into scope: The value can be stored in variable form in the specified range (2 ways)

2) stored value to JavaBean attribute

Instance:

Code for instance Class person:

Package com.entity;/** * Entity class person * @author Administrator * @date July 27, 2016 */public class Person {private String name;private int age;Private String hobby;Public String GetName () {return name;}public void SetName (String name) {THIS.name = name;}public int getage () {return age;}public void Setage (int.) {This.age = age;}Public String Gethobby () {return hobby;}public void Sethobby (String hobby) {This.hobby = hobby;}}

newfile.jsp page:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><!--import jstl Tag library--><%@ taglib uri=" http://java.sun.com/ Jsp/jstl/core "prefix=" C "%><!--Import instance class person--><jsp:usebean id= ' person ' class= ' Com.entity.Person '/> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Results:

<c:remove> tags

<c:remove> tags are variables that delete variables, either from within the specified range or within the range (if no range is specified). This action is usually not

Especially helpful, but it can help ensure that a JSP is scoped to the resource and it is responsible for cleanup.

The <c:remove> tag has the following properties:

Usage of <c:remove> Tags:

The Var attribute is required to remove a variable, and the scope property is optional.

Instance:

Results:


<c:catch> Tags

The <c:catch> tag captures any exception information that occurs on its body and is selectively exposed. Simply for error handling and more gracefully handle this

A problem.

The <c:catch> tag has the following properties:

Usage of <c:catch> Tags:

Can include those error-prone Jstl tags (logic).

Instance:

Results:

<c:if> Tags

The <c:if> tag evaluates an expression that displays its principal content only if the value of the expression is true.

The <c:if> tag has the following properties:

usage of <c:if> Tags:

The IF function in the same program is used to implement the branch condition control.

The Text property is used to store the condition of the judgment and is generally written using the El expression;

The Var attribute is the specified name used to hold the result type of the judgment as true or false;

The scope property is the range used to store the Var attribute.

Instance:

grade judgment based on user-entered scores

Results:

This example is not done, the use of <c:if> tag implementation is cumbersome, we can use the <c:choose> tag and the <c:when> tag to Real

Is.



Java Web Learning (+): Jstl Learning (iii)

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.