JSP expressions (EL)

1. Introduction:

EL (Expression Language) can be used to replace various scripts in JSP to improve programming flexibility and simplify code writing.

Two, EL restrictions:

Variables cannot be declared, and variables need to be set using JSTL or JavaBean Action.

3. The standard format of EL:

The dollar sign is prefixed with a curly brace: ${}

Explanation: When the JSP compiler sees the "${}" format in the attribute, it will generate code to calculate the expression and generate a substitute to replace the value of the expression.

Fourth, the method of disabling EL expressions:

If you want to disable EL expressions, use the page directive to set the value of the isELIgnored attribute to true

<%@ page isELIgnored = "true" %>

After adding the above code, the EL expression will be ignored, otherwise if it is set to false, the EL expression will be valid.

5. Personal summary of minor differences between EL expressions and normal mathematical operators:

(1) Test for equality: == or eq (equal to)

(2) Test for inequality: != or ne (not equal to)

(3) Test whether it is less than: < or lt (less than)

(4) Test whether greater than: > or gt (greater than)

(5) Test whether it is less than or equal to: <= or le (less than or equal to)

(6) Test whether it is greater than or equal to: >= or ge (greater than or equal to)

(7) Modulo: % or mod

(8) except: / or div

(9) Sky: empty

(10) Negation: ! or not

Sixth, give a chestnut (to achieve the parameters of the object obtained through the EL expression):

Code into the body of the jsp page:


        <%--    此处的class是全限定类名--%>
        <jsp:useBean id="tsStudent" class="guida.day06.Student">
            <jsp:setProperty name="tsStudent" property="stuName" value="彦秉成" />
        </jsp:useBean>
        <%--  EL表达式: (Experssion Language) --%>
        EL表达式的值:${tsStudent.stuName}

        <br>
        <%
            String[] names = {"彦秉成","腾从戎","古草"};
            pageContext.setAttribute("names",names);
        %>
        ${names[0]}
        ${names[1]}
        ${names[2]}
        ${names[3]}
<%--        下标虽然超了,但是并不会报数组下标越界的错误,超了的下标会被忽略--%>
<%--        使用 ${}  -> 可避免null显示、避免异常的出现}--%>

 operation result:

Guess you like

Origin blog.csdn.net/zhan_qian/article/details/128019508