JSTL improved JSP to simplify the process of Web page implementation (2)

Source: Internet
Author: User
Tags define exception handling expression html page range variable
js| Process | Web page JSTL Tag Library

So far, I've explained some of the basics and covered the EL syntax. I want to discuss four kinds of jstl tag libraries specifically. I mainly discuss the core library because it's something you have to use, but I'll discuss the rest in detail so you can start it.

First, although I should talk more about the two styles of the JSTL tag library, each of the JSTL tag libraries I mentioned above appear in two versions: one that supports the gown 肊 L, and the other that supports standard JSP expressions. When you introduce any tag library to a JSP page, you define a prefix that specifies the namespace corresponding to the tag in the library.

The four standard tag libraries, and the prefix conventions defined by their JSTL specification, are listed below. Remember: You can define your own prefix, but that's absolutely no good.

Four standard tag libraries



To use the core tag library in the page (in fact, you make your page visible to the tag library's namespace), at the top of your page are the instructions in the following example:

 
   
    
  <%@ taglib prefix= "C" Uri=http://java.sun.com/jstl/core%>
 
   


To use the tag for the tag library, prefix each tag in your page with the prefix you have designed in your include statement:

 
    
     
  <c:out value= "${anexpression}"/>
 
    


Core Database

Let's test the core database in more detail and see his most versatile features first.

Display/Set values and exception handling

The most basic markup for the core library is the c:out tag, which displays the value of an El expression in the page. An expression that uses c:out is usually like this:

 
     
      
  We have <c:out value= "${applicationscope.product.inventorycount}" Escapexml= "true" default= "0"  /> of those Items in the stock.
 
     


In the example above, the Value property is the expression that we send to the page output. I also explained the properties and default properties of the option EscapeXML. The EscapeXML attribute specifies the XML characters (<, >, &, and.) Whether they should be converted to the corresponding character entity code (so that they can have these characters appear in an HTML page); The default property is used in cases where El cannot estimate the value or the value is computed as null.

Note: You do not need to use the C:out action when El Support completely runs through the entire JSP2.0; you can only nest JSP expressions directly in the page.

Another commonly used core action is c:set, which sets a variable in the page. You can use the C:set action in two ways, and the first method sets the variable defined in the var attribute to the value defined in the Value property by using the following method:

 
      
       
  <c:set var= "CustomerID" value= "$param: CustomerNumber" scope= "Session"/>
 
      


The above selection scope property specifies that we want to set the variable CustomerID within the session scope, and if the scope is not set, the scope defaults to the page.

Another powerful use of C:set is to assign the contents of a c:set tagged body to a specified variable:

 
       
         <c:set var= "cellcontents" ><td><c:out value= "${mycell}"/></td> </c:set> 
        


In the previous example, the C:set action defines a variable named cellcontents (in the range of a page) that has content defined in the body of the tag. In this case, the body defines an HTML table cell element, the C:out action in the body of the calculation, and the result of the calculation includes the string direct measure in the body.

As you would expect, Jstl is a little early for exception handling. In a typical JSP page, you have two ways of handling exceptions: trying to capture blocks in small script code embedded directly into a page, or using a JSP errorpage instruction. The JSP errorpage instruction provides a good way to catch all exceptions to handle any possible exceptions in the page. Jstl use a C:catch action to provide a good alternative way. This c:catch action provides a more fine-grained and efficient way to handle exceptions. And there is no Java code embedded in the page. A c:catch action is like this:

 
        
          <c:catch> <!--... Some set of nested JSTL tags below which would is hit on a exception--></c:catch> 
         



C:catch Action has an optional attribute. That is, a variable that points to an exception thrown.

You may not be willing to use the c:remove tag. This tag has properties for variable names and scopes, and can delete the specified variable from the specified range.



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.