JSP-jstl

Instruction label

<% - page instruction -%>
<% - contentType: for what format and coding scheme used to inform the browser parses the response message -%>
<% @ Page contentType = "text / HTML; charset = UTF-. 8 "%>
<% - language: statement of what the current jsp page using a scripting language, the default java -%>
<% @ page language =" java "%>
<% - pageEncoding: set jsp engine translated into java files when what encoding -%>
<% @ page the pageEncoding = "UTF-. 8"%>
<% - the errorPage: used to set the current page to which the exception occurs when a page jump processing -%>
<% page errorPage = @ "error.jsp"%>
<% - isErrorPage: boolean value, true indicates that the current page is a page error handling, false default value -%>
<% @ page isErrorPage = "to true"%>

<% - Static introduced two will merge to generate a java jsp file -%>
<% - <% @ the include File = "copyright.jsp"%> -%>
<% - dynamic introduced, will generating two java files, dynamic introduced by calling methods include -%>
<JSP: Page include = "copyright.jsp"> </ JSP: include>

Nine built-in objects
because the JSP code will be compiled into the final java code, and compiled into service method of servet. Thus the jsp nine built-in objects, the method is serlvet service in nine can be used directly as an object.
EL expression
used to simplify the operation value in the JSP. On el expression is essentially calling the get method. To get the property name and the method name consistent.
> Request parameters: Parameter param name $ {.} / $ {ParamValues parameter name.}
> Scope attributes: Attribute Name} {$
scope value
in an EL expression, provided for the corresponding four four scopes keywords for representing the four scopes
> pageContext -> pageScope
> Request -> requestScope
> sesssion -> sessionScope
> the Application -> applicationScope
// store data to pageContext scope
pageContext.setAttribute ( "msg", "this is a test ");
// the name of the same name in the domain effect, values will be covered, corresponding to modify operation
pageContext.setAttribute (" msg "," PageContext ");




${requestScope.msg}<br>
${sessionScope.msg}<br>
${applicationScope.msg}

JSTL
JSP tag library of standard bricks.
jstl used tags in library:
> Core tag library: core, referred to as C
> Format tag library: format, referred FMT
> tag library function: function, referred to as fn
core tag library
core tag library is the most frequently used jstl tag library encapsulating many effective features such as: the iteration, determining operation functions scope ...
used tags:
<C: SET> for storing data to the specified scope, scope may be omitted, the default is stored in the scope pageContext
<C: SET var = "Demo" value = "Page"> </ C: SET>
<C: SET var = "Demo" value = "the session" scope = "the session"> </ C: SET>
<c: set var = "demo " value = "application" scope = "application"> </ c: set>

<C: OUT> 
<% - for outputting data to the browser, is typically used with an EL expression, when the data is null, the default value is displayed -%>
<C: OUT value = "$ {} demo123" default = "when there is no data, default values are displayed"> </ c: out>

<c: remove> Delete scope value
<% - removing properties from the scope -%>
<C: Remove var = "Demo" scope = "the session"> </ C: Remove>

<c: if> determined
<% - means for determining the conditions, a single branch is determined, the determination condition specified by the properties test -%>
Current Score: $ {score} <br> Level Score:
<C: IF test = "$ {Score GE 90} "var =" FLAG1 "> A - $ {FLAG1} </ C: IF
<C: IF Test =" $ {Score GE 70 && Score lt 90} "var =" FLAG2 "> B - $ {FLAG2} </ C: IF>
<C: IF Test = "$ {Score GE 60 && Score lt 70}" var = "Flag3"> C - $ {Flag3} </ C: IF>
<C: IF Test = "$ lt Score {60}"> D </ C: IF>
<br>
<C: = IF Test "GE Score {60} $" var = "In Flag"> pass </ C: IF>
<C: if test = "{! flag} $"> failed </ c: if>

<c:choose><c:when><c:otherwise> 选择
<%-- 功能类似于switch...case...default --%>
<c:choose>
<c:when test="${score ge 90}">A</c:when>
<c:when test="${score ge 80}">B</c:when>
<c:when test="${score ge 70}">C</c:when>
<c:when test="${score ge 60}">D</c:when>
<c:otherwise>E</c:otherwise>
</c:choose>
<hr>
<c:forEach> 遍历

3. forEach attributes
> var: iteration variable, stored in scope pageContext
> begin: iteration start value
> end: end value iteration
> step: step iteration variable change
> items: to traverse the collection, use EL expression values
> varStatus: the state of the iteration variable
- index: the index, starting from 0
- cOUNT: counts from the beginning
- first: boolean, indicating whether or not the first
- last: boolean, indicating whether the last
- current : Object, the current object value Davis iterative
formatting tag library
is used to format numbers and dates of the
<fmt: formatNumber value = "$ {u.sal}" pattern = "¥ ###, ###, # 0.00 # "> </ FMT: formatNumber>
<FMT: the formatDate value =" $ {} u.birthday "pattern =" the MM-dd-YYYY "> </ FMT: the formatDate>
<FMT: the formatDate value =" $ {U } .loginTime "pattern =" the mM-dd-YYYY HH: mm: SS "> </ FMT: the formatDate>
<FMT: formatNumber> tag has the following attributes:

 

 

 

If the type attribute is the percent or number, then you can use several other formatting numeric attributes. maxIntegerDigits property and minIntegerDigits property allows you to specify the length of integers. If the actual number exceeds the maximum specified maxIntegerDigits, the number will be truncated. Some attribute allows you to specify the number of digits after the decimal point. minFractionalDigits property and maxFractionalDigits property allows you to specify the number of digits after the decimal point. If the actual number exceeds the specified range, this number will be truncated. Digital Packet may be used to insert a comma in each of the three numbers. groupingIsUsed attribute is used to specify whether to use digital packet. When used in conjunction with minIntegerDigits property, it must be very careful to get the desired result. You might use the pattern attribute. This attribute allows you to include the specified character when the digital encoding. The following table lists these characters.

 

 

<Fmt: formatDate> tag has the following attributes:

Guess you like

Origin www.cnblogs.com/sxshe/p/12165920.html