El and Jstl Overview

Source: Internet
Author: User
Tags in domain

One, El expression

1, overview: JSP's built-in expression language, used to replace <%=. %>

${el-expression}

2. Function:

1) Get the data

A. Get Simple properties

${Property Name}: Finds the specified property from Pagecontext,request,session,application,

If a return value is found, the lookup is ended, and if it is not found, returns ""

B. Get Complex data

Get the data in the array

${name in the domain [index]}

Get the data in the list

${name in the domain [index]}

Get data from a map

The name in the ${domain. Key name}

C, get the JavaBean property value

The JavaBean name in the ${domain. Bean Properties}

2) Perform the operation

A, arithmetic

+: addition operation only, string form number can be added

b, relational logical operators

B, Empty

Determines whether a container has a length of 0 (array set list map) and can also determine if an object is empty

${empty List}

C, take anti not empty

D, ternary operators

${3>4? " Yes ":" No "}

3, El's 11 built-in objects

PageContext represents the PageContext of this JSP

Get the project name in the JSP page ${pagecontext.request.contextpath}

Pagescope The value that corresponds to the property name of the page range

Requestscope The value that corresponds to the property name of the request scope

Sessionscope The value that corresponds to the property name of the session scope

Applicationscope The value that corresponds to the property name of the application range

Param is like Servletrequest.getparameter (String name). Callback value of String type

Paramvalues is like Servletrequest.getparametervalues (String name). Callback string[] Type value

The header is like Servletrequest.getheader (String name). Callback value of String type

Headervalues is like Servletrequest.getheaders (String name). Callback string[] Type value

Initparam is like Servletcontext.getinitparameter (String name). Callback value of String type

Cookies are like httpservletrequest.getcookies ()

API for Cookies in Java

GetName (): Gets the name of the cookie

GetValue (): Gets the value of the cookie

Second, jstl expression

1, overview: JSP standard Tag Library language, used to replace Java script

<% @taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C/FMT/FN"%>

2. Classification

1) Core: Kernel class Library

A:c:if judgment

<c:if test= "${el expression}" > content output when satisfied </c:if>

For example: Determine login

<c:if test= "${not Empty name}" >

${name} welcome you!

</c:if>

<c:if test= "${empty name}" >

You have not logged in Please re-login <a href= "${pagecontext.request.contextpath}/login.jsp" > Click Login </a>

</c:if>

B:c:foreach Cycle

Format 1:

<c:foreach begin= "Starting from there" end= "to the End" step= "step" var= "give the variable a name" varstatus= "loop state variable" >

${i}--${vs.count}--${vs.current}<br>

Count: Record count starting from 1 current: What is currently traversed index: index starting from 0

</c:forEach>

Example:<c:foreach begin= "1" end= "step=" 2 "var=" I "varstatus=" vs ">

${i}--${vs.count}--${vs.current}<br>

</c:forEach>

Format 2:

<c:foreach items= "${el get container in domain}" var= "n" >

${n}

</c:forEach>

Example:<c:foreach items= "${map}" var= "en" >

${en.key}--${en.value}<br/>

</c:forEach>

C:c:url Auto-complement project path, automatic URL rewriting

<a href= ' <c:url value= '/foreach.jsp '/> ' >foreach.jsp</a>

Equivalent: <a href= "${pagecontext.request.contextpath}/foreach.jsp" >foreach.jsp</a>

2) FMT: Internationalization

<fmt:formatdatevalue= "date to display" type= "Date/time/both" datestyle= "Full/long/medium/short/default"

Timestyle= "Full/long/medium/short/default" pattern= "Custom Format mode" timezone= "time zone of the display date"

Var= "stores the variable name of the formatted date" Scope= "stores the range of formatted log variables"/>

3) Xml/sql: Obsolete

4) Function Library:

Whether Fn:contains (string,substring) contains

Fn:containsignorrcase (string,substring) ignores case

Whether Fn:endswith (string,suffix) ends with suffix

Whether Fn:startswith (String,prefix) starts with prefix

Fn:substring (String,begin,end) return string begins with Begin end end

Fn:substringafter (string,substring)

Fn:substringbefore (string,substring)

Fn:tolowercase (string) to lowercase

Fn:touppercase (string) to uppercase

Fn:trim (String) remove the leading and trailing spaces

Fn:escapexml (String) xml/html conversion

Fn:indexof (string,substring) returns the first occurrence of the index

Fn:join (Array,separator) returns a string with separator instead of the delimiter in the array

Fn:length (item) return length

Fn:replace (String,before,after) Replacement

Fn:split (string,separator) split string with separator as delimiter returns array


El and Jstl Overview

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.