Getting Started Tutorial: JSP Standard Template Library (bottom)

Source: Internet
Author: User
Tags contains expression
js| Standard | tutorials | templates | Getting Started Tutorial JSTL Tag Library
Jstl is often considered a single label library. But Jstl actually has 4 tag libraries. These tag libraries are summarized as follows:

Core Tag Library? Contains the necessary labels for some Web applications. Examples of core tag libraries include loops, expression assignments, and basic input output.


Format/internationalization Tag library? includes a tag library that is used to parse data. This kind of label will parse the data, such as date, different locale area, etc.


Database Tag library? Contains the tags that are used to access the SQL database. These tags usually only create prototype (prototype) programs. This is because most programs do not directly process database access from JSP pages. Database access should be embedded in EJBS that can be accessed by JSP pages.


XML tag library? Contains tags that are used to access XML elements. Because XML is widely used in web development, XML processing is an important feature of JSTL.
In this article, we'll just make a brief introduction to the core tags. We'll look at a simple example of how to handle the data that users enter into a form. Before we begin to examine the program, we must first look at how Jstl handles the expression, and Jstl's expression processing is done by using the El Expression language, which can only be used in JSP2.0. In the next section, we'll examine the El expression language.

El expression language
One of the main components of JSP2.0 is the new expression language called El. El is widely used in Jstl. However, it is important to remember that El is the function of the JSP rather than the JSTL. The JSP scriptlet code used in JSP2.0 can contain an El expression. The following line of code shows the El in the JSP scriptlet code:

<p>
Your total, including shipping is ${total+shipping}
</p>

As you can see, total and shipping are added to produce HTML and display their values in the browser. These expressions can also be used in jstl tags. An important problem with JSTL1.0 is that JSTL cannot be used on the JSP1.2 version. Because JSP1.2 does not support EL, it is necessary to provide some additional jstl tags to help el use. For example, if you want to use Jstl to display the above expression, you can use the following code.

<p>
Your total, including shipping is <c:out var= "${total+shipping"/>
</p>

It is noteworthy that JSTL does not need JSP2.0 to run. This requirement can be achieved by providing a label that can display an El expression.

Jstl Example
We will examine a simple example of using JSTL. In this example, we will examine a common process in Web applications. We'll see how to submit (POST) a form and process the results of the post. The program code is as follows:

<%@ taglib uri= "Http://java.sun.com/jstl/core" prefix= "C"%>
<title>if with body</title>

<body>
<c:if test= "${pagecontext.request.method== ' POST '}" >
<c:if test= "${param.guess== ' Java '}" >you guessed it!
<br/>

<br/>

<br/>
</c:if>

<c:if test= "${param.guess!= ' Java '}" >you are wrong
<br/>

<br/>

<br/>
</c:if>
</c:if>

<form method= "POST" >guess what computer language
I am thinking of?
<input type= "text" name= "Guess"/>

<input type= "Submit" value= "try!"/>

<br/>
</form>
</body>

This simple Web page displays a form that asks the user to guess the computer language that the program wants. Of course, the computer is thinking "Java". This page starts by checking for "committed". This allows the form and the code that processes the form to be placed on the same page. is implemented through the following JSTL if statement.

<c:if test= "${pagecontext.request.method== ' POST '}" >

Now you see that the,<c:if> tag uses an EL expression to determine whether the request is a post. If the data is posted to the page, the user's guesses are stored in a parameter named "Guest." This is because "guest" is the name of the form entry. We must now check whether this parameter equals "Java". This is done through the following <c:if> tags:

<c:if test= "${param.guess== ' Java '}" >
You guessed it!
</c:if>


As you can see, if the expression is a true,<c:if> tag, the label body is executed. In this article, we begin to examine how JSTL is installed and how it works, and provides some jstl small examples to help you understand.

Jstl's core tag also includes loops, iterators, and variable processing. By using tags, you can iterate in collections, access the user's session data, perform other core tasks, and so on. In addition to the core tag library, XML, database and format tag libraries also provide more advanced use.

(end)

Note: El Expression language translation into El expression language, some translated into El Express language, is a meaning.

Translated by Caiyi0903 (willpower), 2004.2.19



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.