Jstl and El Common tags

Source: Internet
Author: User
Tags class operator coding standards control label map class tld

Jstl and Elel-related concepts jstl are generally used in conjunction with El expressions to implement a Java code snippet that does not appear in the JSP. So let's learn that El expression El is primarily used to look up data in the scope and then perform simple operations on them; it is not a programming language, not even a scripting language. Usually works with the JSTL tag to represent complex behavior with simple and convenient symbols. El Basic format el expression format: delimited with dollar sign ($), content included in curly braces ({}); for example: ${logininfobean.suser} In addition, you can combine multiple expressions with static text to construct dynamic property values through string literals, for example: Hello {logininfobean.suser} ${logininfobean.spwd} el syntax composition-An identifier El expression consists of identifiers, accessors, literals, and operators. Identifiers are used to identify the data objects that are stored in the scope. EL has11a reserved identifier that corresponds to 11 El implicit objects. In addition to the 11 implicit objects, it is assumed that all other identifiers are used to identify scope variables. identifier Example: ${ABC} is equivalent to<%=pagecontext.findattribute ("abc")%>${og_1}<%=pagecontext.findattribute ("og_1")%>..... And so on; The identifier inside {} represents the name of the data in the scope except for 11 reserved words. The requestscope in ${requestscope} is one of 11 El implicit objects that no longer represents the data in the scope, but rather represents the request scope; The El hidden object pagecontext PageContext instance corresponds to the current page's processing Pagescope the map class associated with the name and value of the page scope property Requestscope  The map class associated with the name and value of the request scope property Sessionscope The map class associated with the name and value of the session scope property Applicationscope the map class associated with the name and value of the Application scope property param The map class that stores the primary value of the request parameter by name Paramvalues the map class that stores all the values of the request parameter as a string array in the header of the map class to store the main value of the request header by name Headervalues all the values of the request header as String arrays The Map class cookie stores the map class of the cookie that is included in the request by name Initparam the map class that stores the WEB application context initialization parameters by name the El accessor accessor is used to retrieve the object's attributes or elements of the collection. Accessor: Get relevant data example by "[]" or "." Symbol: ${userbean.suser} or ${userbean["Suser"}//gets the value of the Suser attribute in the output bean;${mctype["id"}//gets the value of the key in the map corresponding to the ID;the EL operator operator allows the combination and comparison of data and text. 
El Operator: class operator arithmetic operator+ 、-、 *,/(or DIV) and% (or mod) relational operators = = (or eq),! = (or NE), < (or LT), > (or GT), <= (or Le), and >=(or GE) logical operators&& (or), | | (OR) and!(or not) validation operator empty validation operator (empty): Especially useful for validating data. The empty operator takes a single expression as its variable (that is, ${empty input}) and returns a Boolean value that indicates that the result of evaluating the expression is not an "empty" value. The result of evaluation isNULLExpression is considered empty, that is, a collection or array with no elements. If the argument is the result of a String evaluated with a length of zero, the empty operator also returnstrue. The El literal indicates a fixed value-a number, a character, a string, a Boolean, or a null value. In an EL expression, a number, a string, a Boolean value, and aNULLcan be specified as literal values. Strings can be bounded by single or double quotation marks. The Boolean value is specified astrueAndfalseWhat is Jstl jstl (JSP standard tag LIBRARY,JSP standards Tag Library) is a constantly perfected open source JSP tag library that is maintained by Apache's Jakarta team. JSTL1.0Consists of four custom tag libraries (core, format, XML, and SQL) and a pair of common tag library validators. The core tag library provides custom actions to manage data by limiting the scope of variables, as well as performing iterations and conditional actions on page content. It also provides tags for generating and manipulating URLs. The Format tag library defines the operations that are used to format data, especially numbers and dates. It also supports the internationalization of JSP pages using localized resource bundles. The XML library contains tags that manipulate the data represented by XML, and the SQL Library defines the operations that are used to query the relational database. Two JSTL tag library validators allow developers to enforce coding standards in their JSP applications. If you want to use JSTL, you must refer to the Jstl.jar and Standard.jar two packages. Why use Jstl our JSP is very handy for developing information presentation pages, and you can embed Java code (scriptlet, expressions, and declarations) code to implement related logical controls. Look at the procedure below. However, this will lead to the following problems: JSP maintenance difficulty increased, error prompt is not clear, not easy to debug, the division of labor is not clear, (that is, JSP developers are artists and programmers), and ultimately increase the development costs of the program; JSTL enables JSP developers to reduce the need for scripting elements, even without them, to avoid the associated maintenance costs. Make the division of labor more clear. <%if(Session.getattribute ("user"). Equals ("member")) {%> <p>welcome, member!</p><%}Else{%> <p>welcome, guest!</p><%}%>Jstl is generally used in conjunction with EL, so look at El first.
There are two ways to deploy JSTL JSTL deployment in EE applications: Existing engineering deployments will Jstl.jar and Standard.jar two packages to the current project WebRoot/Web-inf/in the Lib directory, the relevant. tld files are tested in the existing project WebRoot/web-INF directory, or it can be deployed directly to the JSP using JSTL when new projects are deployed on existing projects through Eclipse- core Tag Library core usage in JSP: Add in Web. XML<jsp-config> <taglib> <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri><taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> </jsp-config>adding in the JSP file<%@ taglib prefix= "C" uri= "http://Java.sun.com/jsp/jstl/core "%> or <%@ taglib prefix=" C "uri="/web-inf/c.tld "%>Use <c:out value= "HelloWorld"/>
the Operation scope variable label of the core gets the variable in the output scope.<c:out >Property: Value [default] [EscapeXML] defines the scope of the variable<c:set >Properties: Valuevar[scope] Delete a variable in scope<c:remove >Property:var[Scope]core Condition control label Single branch condition<c:if >Properties: Test [var] [scope] multi-branch condition<c:choose ><c:when >Properties: Test<c:otherwise >the other tag outputs of the core are converted into URLs:<c:url >Property: Value [Context] [var] [scope] and<jsp:include >similar to content that contains other pages:<c:import >Properties: URL [context] [charencoding] [var] [scope] redirection<c:redirect >Properties: URL [context] and<c:url><c:import><c:redirect>Used in conjunction to pass the parameter<c:param >properties: Loop control label for name Valuecore simple loop<c:foreach >  var= ' Item ' begin= ' 5 ' end= ' step= '2 ' varstatus= ' implementation iterations (traversal) <c:foreach > items=' var= ' item ' varstatus=The ' attribute varstatus is similar to the Var setting of a scope variable; just the varstatus scope variable is the object containing the run state; This object contains the following properties: Current index count first last begin end S Tep Simple Cycle<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "%><%@ taglib prefix=" C "uri="/web-inf/c.tld "%>var= "I" step= "1" begin= "1" end= ">"${i}<br> </c:forEach></body>Loop Iteration<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "%><%@ taglib prefix=" C "uri="/web-inf/c.tld "%>var= "McBean" items= "${mclist}" varstatus= "Mcstatus" >Current traversal index: ${mcstatus.index}; Product name: ${mcbean.sname}; .... <br></c:forEach></body>
 
  
 
use JSTL in JSP-Format  Tag Library use of format in JSP: Add in Web. XML<jsp-config> <taglib> <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri><taglib-location>/WEB-INF/fmt.tld</taglib-location> </taglib> </jsp-config>adding in the JSP file<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jstl/fmt"%>Use<fmt:formatdate value= "" pattern= "Yyyy-mm-dd"/>format Common label formatted output date:<fmt:formatdate> Value typevarPatterntype Value: Short: 10/19/00 6:07pmmedium:oct19, 2000 6:07:01PMLong: October 19, 2000 6:07:01PM Mdtfull:thursday, October19, 2000 6:07:01PM MDT Example:<fmt:formatdate value= "" pattern= "Yyyy/mm/dd"/>formatted output number:<Fmt:formatnumber> ValuevarPattern Example:<fmt:formatnumber value= "" pattern= "###.##"/>Format Instance<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "%><%@ taglib prefix=" FMT "uri="/web-inf/fmt.tld "%>

Jstl and El Common tags (rpm)

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.