Javaweb part6---jstl and El expressions

Source: Internet
Author: User

Jstl/java standard Tag library/with El expression
Replace Java code in JSP

El expression Operation symbol
GT >
Lt <
GE >=
Le <=
EQ = =
Ne! =
&&
or | |
Not!
xx.xxx xx["xxx"]
xx?xxx:xxx;

Tag Library recommended prefixes
Core/c
Xml/x (not working with XML files in the JSP)
Fmt/fmt
Sql/sql (do not manipulate database in JSP)
Functions/fn

< prefix: Label Name Property name = Attribute Value Property Name = property value >
Core Tag Library
<c:out > Output
Value supports El expressions for specifying output content
EscapeXML supports El default to True to escape special symbols
Default when value is NULL, the value of the default is output;

<c:set> store data in a web domain, or in other collections;
Value supports El. Object
var does not support El string specifying variable name
Scope does not support elstring specified range page/request.session.application
Target supports Elobjecttarget and Paroperty use
Property Support Elstring
<c:set scope= "Request" var= "name" value= "Rupeng" ></c:set>
Scope and Var use the request on behalf of the web domain scope var to represent the variable name
The value is obtained by ${requestscope.name} rupeng/
<%person p1=new person ();
P1.setname ("Yqw");
Request.setattribute ("person", p1);

Person P=new person ();
Session.setattribute ("Person", p);//Put the object P with the property name as Request%>
<!--target is equivalent to using Findattribute () to go to four fields to find the object with the property as person. Find both return--
<!--and the object is person p. You can set his property name. And then take it out .-->
<c:set target= "${sessionscope.person}" property= "name" value= "Jerry" ></c:set>
${person.name}<br/>${sessionscope.person.name}<br/>

<c:remove var= "name" scope= "Request" >
Delete the value of the request in this range with the property name name.

Catch label
Use <c:catch var= "exception" for potentially abnormal code ></c:catch> wrap it Up
Then call <c:out ${pagescope.exception}/> to output the exception object with three properties of this object
getmessage/exception Information getcause/exception reason getstacktrace/the number of calls to the exception

If Core label
Test support El expression Boolean//conditional expression This is the if tag must have.
var does not support El String to declare a variable to accept the result of test
Scope does not support El string default deposit range is page, you can specify web domain

<c:if test= "${age eg" var= "RS" >
Everyone is an adult.
</c:if>
<c:out value= "${rs}"/>
Here, test is the conditional expression Var, which indicates the result of this conditional expression
test= "Empty Name" indicates whether the property of the object pointed to by name is empty.

<c:foreach items= "${persons}" var= "P" >
${P} can output each object inside the persons;
</c:forEach>

Multiple conditional expressions
<c:choose>
<c:when test= "conditional expression 1" >
Execute code block
</c:when >
<c:when test-"conditional expression 2" >
Execute code block
</c:when>
</c:choose>when can have multiple expressions,<c:otherwise> optional

<c:redirect url= "/"/>

<a href= "<c:url value= '/index.jsp ' >
<c:param name= ' name ' value= ' 999 ' ></c:param>
<c:param name= ' id ' value= ' ></c:param></c:url> ' > Hyperlinks </a>


When Jstl, note that when invoking the. Name property of an object, the value of name is not related to the object's private variable. Determined by the Get/set method.

Javaweb part6---jstl and El expressions

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.