Import and use jstl in myeclipse

Source: Internet
Author: User
Tags map class tld

1. Import jstl

Method 1:

Right-click your project and select the Add jstl library option in myeclipse.

Method 2:

Create a project. In the "jstl support" column, add jstl libraries to web_inf/lib folder and click Finish.

Ii. Use jstl

1. Introduction to jstl
JSP standard tag Library (jstl) is a set of custom tag libraries that implement common functions in Web applications, these functions include iteration and condition judgment, data management formatting, XML operations, and database access.
Jstl 1.0 has four custom tag libraries: Core, format, XML, and SQL.
1. The core tag Library provides custom operations to manage data by limiting the scope of variables and performing iteration and conditional operations on page content.
2. The format tag library defines operations for formatting data (especially numbers and dates. It also supports internationalization of JSP pages using localized resource bundle.
3. the XML library contains some tags that are used to manipulate data expressed in XML.
4. the SQL database defines the operations used to query relational databases.

2. Expression Language)
1. Implicit object (common)
1) requestscope: Map class associated with the name and value of the Request scope attribute
2) sessionscope: the map class associated with the name and value of the session scope attribute
3) applicationscope: Map class associated with Application Scope attribute names and values
4) pagination: the map class associated with the name and value of the page scope attribute
5) Param: Map class that stores the main values of Request Parameters by name
6) paramvalues: all values of the request parameters are stored as map classes in the string array.
2. El expression format:
It is bounded by the dollar sign ($) and the content is included in curly brackets ({}). For example: $ {value}
3. El accessors: Use the dot operator (.) and square brackets operator ([]).
1) Point operators are usually used to access the characteristics of objects. For example, in the expression $ {user. firstname}, use the dot operator to access the firstname feature of the object referenced by the User Identifier.
2) The square brackets operator is used to retrieve elements of arrays and collections. In the case of arrays and Ordered Sets, place the subscript of the element to be retrieved in square brackets. For a set that implements the java. util. map interface, the square brackets operator uses the associated key to find the value stored in the ing. Specify the key in square brackets and return the corresponding value as the expression value.
3) vertex operators and square brackets operators may be interchangeable to some extent.
4. El Operator
1) Arithmetic Operators: +,-, *,/(or Div), and % (or mod)
2) Relational operators: = (or eq ),! = (Or NE), <(or LT),> (or Gt), <= (or Le), and> = (or GE)
3) logical operators: & (or and), | (or), and! (Or not)
4) Verification OPERATOR: empty
Iii. Common jstl core tags
1. Set definition variable Tag: defines variables with limited scope
Syntax:
1): <C: Set Value = "value" Var = "varname" [scope = "{page | request | session | application}"]/>
2): <C: Set Var = "varname" [scope = "{page | request | session | application}"]> body content </C: Set>
2. Out print Tag: Display expression value, replace <% = variablename %> in JSP scriptlet
Syntax:
1): <C: Out value = "$ {variablenam}" [escapexml = "{true | false}"]> default value </C: Out>
2): <C: Out value = "value" escapexml = "{true | false}"] [default = "defaultvalue"]/>
3. foreach loop tag (for/while): provides the ability to loop a specified number of cycles (for syntax 2) or on a data structure (collection/array) (For Syntax 1)
Syntax:
1): <C: foreach [Var = "varname"] items = "collection" [varstatus = "varstatusname"] [begin = "begin"] [END = "end"] [step = "step" ]> body content </C: foreach>
2): <C: foreach [Var = "varname"] [varstatus = "varstatusname"] Begin = "begin" end = "end" [step = "step"]> body content </C: foreach>
4. fortokens cycle MARK: allows loop of a string value and uses the selected character as the delimiter between tokens.
Syntax:
<C: fortokens items = "stringoftokens" delims = "delimiters" [Var = "varname"] [varstatus = "varstatusname"] [begin = "begin"] [END = "end"] [step = "Step"]> body content </C: fortokens>
5. If condition evaluation mark (IF): evaluates a specific value only when the specified test condition is true, without the "else" condition-either execution or ignore execution body
Syntax:
1): <C: If test = "testcondition" Var = "varname" [scope = "{page | request | session | application}"]/>
2): <C: if test = "testcondition" [Var = "varname"] [scope = "{page | request | session | application}"]> body content </C: If>
6. Choose condition evaluate tag (switch-case/if-else): Use nested when TAG (similar to case) and otherwise tag (optional, similar to default)
Syntax:
1): <C: Choose> body content (<when> and <otherwise> subtags) </C: Choose>
2): <C: When test = "testcondition"> body content </C: When>
3): <C: otherwise> conditional block </C: otherwise>
7. Remove Delete variable Tag: Used to delete a variable with a limited scope
Syntax:
<C: Remove Var = "varname" [scope = "{page | request | session | application}"]/>
4. Start Using jstl
1. required files:
1) JAR file: jstl. jar, standard. Jar. is usually placed in the lib directory
2) TLD file: C. TLD, usually in the WEB-INF directory, modify the Web. xml file according to the location of the TLD File
3) An example of Web. xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype web-app public "-// Sun Microsystems, Inc. // DTD web application 2.3 //" http://java.sun.com/dtd/web-app_2_3.dtd ">
<Web-app>
<Taglib>
<Taglib-Uri> http://java.sun.com/jstl/core </taglib-Uri>
<Taglib-location>/WEB-INF/C. TLD </taglib-location>
</Taglib>
</Web-app>
2. Declare the tag library on the JSP page:
<% @ Taglib prefix = "C" uri = "http://java.sun.com/jstl/core" %>
V. References
Jstl specification: http://java.sun.com/products/jsp/jstl/index.jsp

IBM: http://www.ibm.com/developerworks/cn/java/j-jstl0211/
Jstl 1.0 download: http://www.apache.org/dist/jakarta/taglibs/standard-1.0/
Jstl1.0 specifications: http://www.jcp.org/aboutJava/communityprocess/first/jsr052/index.html
Language: http://www-900.ibm.com/developerWorks/cn/java/j-jstl0211/
6. Example of using core tag in combination:
<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Taglib uri = "http://java.sun.com/jstl/core" prefix = "C" %>
<HTML>
<Head>
<Title>
Usejstlcoretag
</Title>
</Head>
<Body bgcolor = "# ffffff">
<H1>
Jstl core tag
</H1>
Taglib declare <br/>
& Lt; % @ taglib uri = "http://java.sun.com/jstl/core" prefix = "C" % & gt;
<Table border = "1">
<Tr>
<TD> tag
</TD>
<TD>
Example
</TD>
<TD>
Result
</TD>
</Tr>
<Tr>
<TD>
Set
</TD>
<TD>
& Lt; C: Set Value = "sessionvariablevalue" Scope = "session" Var = "sessionvariable"/& gt;
</TD>
<TD>
<C: Set Value = "sessionvariablevalue" Scope = "session" Var = "sessionvariable"/> & nbsp;
</TD>
</Tr>
<Tr>
<TD> out
</TD>
<TD>
& Lt; C: Out value = "$ {sessionscope. sessionvariable}" default = "NONE" escapexml = "false"/& gt; <br/>
<Br/>
& Lt; C: Out value = "$ {sessionscope ['sessionvariable']}" default = "NONE" escapexml = "false"/& gt;
</TD>
<TD>
<C: Out value = "$ {sessionscope. sessionvariable}" default = "NONE" escapexml = "false"/> <br/>
<Br/>
<C: Out value = "$ {sessionscope ['sessionvariable']}" default = "NONE" escapexml = "false"/>
</TD>
</Tr>
<Tr>
<TD>
Remove
</TD>
<TD>
& Lt; C: Remove Var = "sessionvariablevalue" Scope = "session"/& gt;
</TD>
<TD>
<C: Remove Var = "sessionvariable" Scope = "session"/>
</TD>
</Tr>
<Tr>
<TD colspan = "2">
After remove, & lt; C: Out value = "$ {sessionscope. sessionvariable}" default = "NONE" escapexml = "false"/& gt;
</TD>
<TD>
<C: Out value = "$ {sessionscope. sessionvariable}" default = "NONE" escapexml = "false"/>
</TD>
</Tr>
<Tr>
<TD>
Foreach
</TD>
<TD>
& Lt; Table & gt;
& Lt; tr & gt;
& Lt; C: foreach begin = "1" End = "10" step = "1" Var = "loop" & gt;
& Lt; TD & gt;
& Lt; C: Out value = "$ {loop}"/& gt;
& Lt;/TD & gt;
& Lt;/C: foreach & gt;
& Lt;/tr & gt;
& Lt;/table & gt;
</TD>
<TD>
<Table>
<Tr>
<C: foreach begin = "1" End = "10" step = "1" Var = "loop">
<TD>
<C: Out value = "$ {loop}"/>
</TD>
</C: foreach>
</Tr>
</Table>
</TD>
</Tr>
<Tr>
<TD>
Fortokens
</TD>
<TD>
& Lt; C: fortokens Var = "token" delims = "#,; 4" items = "0 #, A, B, C #,; 4D "begin =" 3 "End =" 10 "step =" 2 "& gt;
& Lt; C: Out value = "$ {token}" & gt;
& Lt;/C: Out & gt;
& Lt;/C: fortokens & gt;
</TD>
<TD>
<C: fortokens Var = "token" delims = "#,; 4" items = "0 #, 6 #, 7;, a, B, C #,; 4d "begin =" 3 "End =" 10 "step =" 2 ">
<C: Out value = "$ {token}">
</C: Out>
</C: fortokens>
</TD>
</Tr>
<Tr>
<TD>
If
</TD>
<TD>
& Lt; C: If test = "$ {sessionscope. sessionvariable = 'none'}" & gt;
There is not sessionvariable
& Lt;/C: If & gt;
<Br/>
& Lt; C: If test = "$ {sessionscope. sessionvariable! = 'None'} "& gt;
The value of sessionvariable is not none
& Lt;/C: If & gt;
</TD>
<TD>
<C: If test = "$ {sessionscope. sessionvariable = 'none'}">
There is not sessionvariable
</C: If>
<C: If test = "$ {sessionscope. sessionvariable! = 'None'} ">
The value of sessionvariable is not none
</C: If>
</TD>
</Tr>
<Tr>
<TD>
Choose
</TD>
<TD>
& Lt; C: Choose & gt; <br/>
& Lt; C: When test = "$ {empty sessionscope. sessionvariable}" & gt; <br/>
There is not sessionvariable
& Lt;/C: When & gt; <br/>
& Lt; C: otherwise & gt; <br/>
The value of sessionvariable is not none
& Lt;/C: otherwise & gt; <br/>
& Lt;/C: Choose & gt; <br/>
</TD>
<TD>
<C: Choose>
<C: When test = "$ {empty sessionscope. sessionvariable}">
There is not sessionvariable
</C: When>
<C: otherwise>
The value of sessionvariable is not none
</C: otherwise>
</C: Choose>
</TD>
</Tr>
</Table>
<Form method = "Post">
<Table>
<C: foreach Var = "loop" begin = "1" End = "10" step = "1">
<Tr>
<TD>
<Input type = "checkbox" name = "checkbox" value = "<C: Out value = '$ {loop}'/>"/> <C: out value = '$ {loop}'/>
</TD>
</Tr>
</C: foreach>
</Table>
<Input type = "hidden" name = "hiddenvar" value = "hiddenvalue"/>
<Input type = "Submit" value = "Submit"/>
</Form>
& Lt; C: Out value = "Param. hiddenvar" default = "NONE"/& gt;
<C: Out value = "$ {Param. hiddenvar}" default = "NONE"/>
<C: If test = "$ {not empty Param. hiddenvar}">
<P>
After click submit button, display following:
</P>
You select:
<C: foreach Var = "checkboxvalues" items = "$ {paramvalues. checkbox}" varstatus = "status">
<C: Out value = "$ {checkboxvalues}"/>
<C: If test = "$ {! Status. Last} ">,
</C: If>
</C: foreach>
</C: If>
<P> Please refer to the following parts of the source file on this page to experience the role of the escapexml attribute of the out Tag. <Br/>
<C: Set Var = "tempvar" Scope = "page">
<PRE> <&> </PRE>
</C: Set>
Set escapexml = false, output:
<C: Out value = "$ {tempvar}" escapexml = "false"/>
Set escapexml = true, output:
<C: Out value = "$ {tempvar}" escapexml = "true"/>
</P>
</Body>
</Html>

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/baobeisimple/archive/2007/02/08/1505243.aspx

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.