js| Process | Web page Process Control
let's turn to the JSTL Process control and condition tag. If you've already used conditional and process control statements in any language, there's nothing new in theory.
c:if action to process a test of a simple conditional statement. Calculates the value of a Boolean expression in a test property, and the contents of the body of the calculation if the expression is true. In the following action, we also describe the option var attribute. For later use, the Var property saves the test results on the page (if no other scope attribute is specified).
<c:if test= "${status.totalvisits = = 1000000}" var= "visits" > You are the millionth visitor Congratulations!</c:if>
below we show support for Jstl with C:choose, C:when, and c:otherwise exchange logic. A set of C:when actions may be included in an alternative tag, and if any expression in the C:when block evaluates to true, the test in the C:choose action is not calculated. If there is not one Test in the C:when block that evaluates to true: if the C:otherwise action content appears, the contents of the C:otherwise action are calculated:
<c:choose><c:when test= "${item.type = = Book }" >...</c:when><c:when test= "${item.type = = Electronics} ">...</c:when><c:when test=" ${item.type = = Toy} ">...</c:when><c:o Therwise>...</c:otherwise></c:choose>
The
C:foreach action provides an easy way to iterate over the elements of a collection. If you want to iterate over only a portion of a collection, you can specify the starting point, end point, and a recursive increment by using the begin, ending, and step properties respectively. In the following example, we iterate over the contents of a collection in the variable customernames, in each loop, the next element is entered into the variable name and evaluated in the body of the C:foreach action:
<table><c:foreach var= "name" items= "${customernames}" ><tr><td><c:out value= "${name}"/ ></td></tr></c:forEach></table>
Remember the Java StringTokenizer class? With the C:fortokens action, you can use JSTL to get similar functions. This piece of the program can use the delimiter defined in the Delims property to iterate through the entries in the items string property. Note that the Items property does not have to be a direct amount of characters; it can be any valid El expression:
<table><c:fortokens items= "47,52,53,55,46,22,16,2" delim= "," var= "Dailyprice" ><tr><td> <c:out value= "${dailyprice}"/></td></tr></c:fortokens></table>
in the next complete jstl page, I list all the parameters that have been passed to the page. The Param and Paramvalues objects are Java map sets that map a keyword to one or more values. In this case, we found the keyword for each mapentry for the collection, the parameter name, and used keywords to find all the parameter values associated with the keyword:
<%@ taglib uri= "Http://java.sun.com/jstl/core" prefix= "C"%>
Other Action
We also need to discuss some of the other important core tag library actions. A potential problem scope in web implementation is related to URL encoding. Without URL encoding, a word Furu a space in a URL passed in a Web page may confuse the Web server. URL encoding ensures that these special characters are replaced with characters that do not cause confusion. The following example defines a URL in the variable Myurl that consists of a URL and a series of arguments Myurl. The URL action (note that the action here is only in the JSTL sense) guarantees that all characters are encoded correctly:
<c:url value= "Http://acme.com/exec/register" var= "Myurl" ><c:param name= "name" Value= "${param.name}"/><c:param name= "Country" value= "${param.country}"/></c:url><a href= <c
: Out value= "${myurl}"/> >Register</a>
In the above code, the Param action simply defines a set of name-value pairs. The
JSP allows designers to use the!--? Xml:namespace PREFIX = JSP/--> directives include the contents of other pages. Jstl expands the concept with Jstl c:import action. The main advantage of C:import is that you can specify an arbitrary URL, or you can include the contents of a page outside your Web application (anywhere in the world) or another Web application on your server.
None of the methods that handle HTTP redirection are incomplete for a set of HTTP-related tags. JSTL supports it with C:redirect action.
Internationalization Tag Library
In the discussion of JSTL support internationalization, I assume you have a reasonable understanding of the following topics:
Resource Bundles and Java how to find them
Locale class
Resource Bundle lookup and Messageformat class
Local encoding and its relationship to Java internationalization
Java text and data formatting
I'll discuss in the next two sections The Internationalization tag library. In the first section, I include the formatting and interpretation-related actions you might use (it initially corresponds to the class in the Java.text package), although you may have to use it even though you have not developed a fully internationalized application. In the second part, I explained more about the internationalization of the action.
If there is a remote possibility, your application will be used outside of your home country. If you are based on international support from the outset, it will be easier to develop. No matter what method you use to develop, even a method that is as easy to use as JSTL, it is very useful to start with internationalization support.