JSTL Application 2

Source: Internet
Author: User
First: c: iftest condition expression var variable name scope range Second: c: iftest condition expression var variable name scope range program body c: if iftest is equal to true, if the Execution Code is not equal to true, then if var is not executed, it is a Boolean variable. It is used to save the condition result. scope Is a range. below is

First: c: if test = conditional expression var = variable name scope = range/Second: c: if test = conditional expression var = variable name scope = range body/c: if test is equal to true, if the Execution Code is not equal to true, then if var is not executed, a bool variable is used to save the condition result. scope is a get range. below is

First:

Second:

Program body

If test is equal to "true", the Code is not executed if it is not equal to true.

Var is a Boolean variable used to save the conditional results.

Scope is a value range.

The following is a simple code:

<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>


Insert title here







// When assigning values to test, you must convert the expression result to a string.
Code segment



Code segment

Instance code

<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>


Insert title here











And implements the key-value pairs of the java. util. Map interface.

Or Array

First:

Is an iteration set or key-value pair that is unknown for the number of iterations

Program body .....

VarStatus has four attributes

Whether first is the first element

Whether last is the last element

Count the number of current iterations

Index indicates the subscript of the current element.

Second:

// This is similar to the for Loop

Loop body

The second method is relatively simple, so I only write iteration instances:

<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>


Insert title here


<%
String [] name = {"one", "two", "three", "four", "five "};
Request. setAttribute ("name", name); // arrays in java are also referenced data types
%>



First element



Last Element





4,

It can be used to iterate a character string. This character string is separated by multiple symbols.

Usage and Similar

[Step = "step"] [varStatus = "Iteration state variable here is the same as above"]>

The following is a simple example.

<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>


Insert title here


<%
String str = "Zhang San | Li Si | Wang Wu | Ma Liu ";
Request. setAttribute ("strName", str );
%>




And other subprograms

<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>


Insert title here




6, We can use this method to redirect a page without parameters.

"> Click home

If the parameter is included, a body is required.




In contrast, we can see that the second generated url is index. jsp; jsessionid = C1C2E5EAE9F2797E44971A409A1F01D5? Param = % b2 % ce % ca % fd with a parameter

The first url without parameters is idnex. jsp.

7, When a request arrives, it will automatically jump to the specified webpage and response. sendRedirect (String url); similar

When the page is added, the http://www.baidu.com is

Http://www.baidu.com /? Param1 = 1, 555

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.