EL expression

xiaoxiao2021-03-06  39

<% @ taglib prefix = "c" uri = "

http://java.sun.com/jstl/core_rt "%>

FOREACH:

VAR = "item"

Begin = "0"

End = "9"

Step = "1"

Varstatus = "var">

......

OUT:

C: OUT> Outputs the content in value to the current position, which is also the LoginInfo object

The username property value outputs to the current location of the page.

$ {...} is the syntax of Expression Language (EL) in JSP2.0. It defines an expression.

The expression can be a constant (as above), or a specific expression statement (such as the foreach cycle body)

Case). Typical cases are as follows:

Ø {loginifo.username}

This indicates the use of the UserName property of the reference LoginInfo object. We can pass "."

With the properties of the object, you can use the "[]" reference object properties, such as $ {loginInfo [username]}

The same effect is achieved with $ {logininfo.username}.

"[]" The meaning of the reference method is that there is a special character in the property name, such as "." Or "-",

At this point, "[]" must be used to get the attribute value to avoid the conflict on the syntax (the system should be avoided when developing

This phenomenon appears).

The same as the same JSP Script is approximately as follows:

LoginInfo LoginInfo =

(LoginInfo) session.getattribute ("loginInfo");

String username = loginifo.getusername ();

It can be seen that EL has greatly saved encoding amount.

Another problem drawn here is that where else will find the loginInfo object, for

For this expression, you will first find it from the current page.

No definition loginInfo, if you don't find it, you can go to Request, Session,

Looking for the Application range until you find it. If it is still not found to find a match until

The variable returns NULL.

If we need to specify the range of variables, you can specify a search range in the EL expression:

$ {PageScope.loginfo.username}

$ {requestscope.loginifo.username}

$ {sessionscope.loginifo.username}

$ {ApplicationsCope.loginifo.username}

In Spring, all the result data returned by all logical processing units will be placed as Attribute

Return to the HTTPServletRequest object (see Spring Source Code)

Org.springframework.web.servlet.view.internalResourceView.

The implementation code of the ExposemodelasRequestAttributes method), that is, Spring

In the MVC, the resulting data objects are RequestScope defaults. Therefore, in Spring MVC, the following addressing methods should be used with caution:

$ {sessionscope.loginifo.username}

$ {ApplicationsCope.loginifo.username}

Ø {1 2}

The result is an expression calculation result, ie integer value 3.

Ø {i> 1}

If the variable value I> 1, the Bool Type TRUE will be returned. Compared with the previous example, you can find that EL will

Move different data types according to the expression calculation results.

The expression of the expression is approximately the same as the expression in the Java code.

IF / choose:

*

The determination condition is generally an EL expression.

does not provide an else clause, it may be some inconvenience when using it, at this time we can pass

Tag to achieve a similar purpose:

*

!

Similar to the Switch statement in Java, provides a simplified processing method under complex decision conditions. its

The clause is similar to the CASE clause, and it can have multiple times. The above code, output "*" when odd lines,

And the even line output "!".

转载请注明原文地址:https://www.9cbs.com/read-63341.html

New Post(0)