JavaWeb-EL / JSTL

EL expression

  • What is EL expression?
    EL (Express Lanuage) expression can be embedded within the jsp page, EL (Express Lanuage) expression can be embedded within the jsp page, the purpose is to replace EL appear to write jsp page script.
  • Effect:
    the EL most important role is to obtain data of the four domains
    fetch data from among the four fields:
pageContext ${pageScope.key}
request ${requestScope.key}
session ${sessionScope.key}
application ${applicationScope.key}

Shorthand:

/*依次从pageContext域,request域,session域,application域中	获取属性
在某个域中获取后将不在向后寻找
*/
${EL表达式} 
EL从四个域中获得某个值<${key}
  • EL built 11 objects
pageScope JSP data acquired in the field of pageScope
requestScope JSP data acquired in the field of requestScope
sessionScope JSP data acquired in the field of sessionScope
applicationScope JSP data acquired in the domain applicationScope
param request.getParameter()
paramValues rquest.getParameterValues()
header request.getHeader(name)
headerValues request.getHeaderValues()
Initfrm this.getServletContext().getInitParameter(name)
cookie request.getCookies()—cookie.getName()—cookie.getValue()
pageContext pageContext get eight other objects, get the name of the current project, $ {pageContext.request.contextPath}
  • EL executing the expression
    internal operation may be performed, as long as the result
${1+1}
${empty user}
${user==null?true:false}

JSTL

  • What is JSTL
    JSTL (JSP Standard Tag Library), JSP Standard Tag Library, you can embed business logic and other functions to complete the form using the tag in jsp page, with the aim jstl appear also to be in place as el script code jsp page.
  • JSTL standard tag library has five sub-libraries
Core: Core Library http://java.sun.com/jsp/jstl/core prefixes: c
I18N: international library http://java.sun.com/jsp/jstl/fmt prefix: fmt
SQL http://java.sun.com/jsp/jstl/sql prefix: sql
XML http://java.sun.com/jsp/jstl/xml prefix: x
Functions http://java.sun.com/jsp/jstl/functions prefix: fn
  • The introduction of tag libraries
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  • if the label
    by binding EL expression is used together, the data taken from the domain EL, or the determination traversal using JSTL
<c:if test="${1==1 }">满足条件时,中间的内容才会显示出来</c:if>
  • foreach tags
    first: the ordinary cycle
<c:forEach begin="0" end="5" var="i">
    ${i}<br/>
</c:forEach>

The second: the increase for loop

<c:forEach items="${list}" var="str">
    ${str}
</c:forEach>
Published 25 original articles · won praise 0 · Views 274

Guess you like

Origin blog.csdn.net/qq_42219004/article/details/105329601