The solution to the problem that the EL expression in the jsp page is treated as a string and does not display a value

  • 2021-11-01 04:15:05
  • OfStack

When I practiced my hand, I encountered the phenomenon that EL expression was treated as a string without correct parsing. Javaee5 used in the project at that time,


<web-app version="2.5" 
xsi:schemaLocation="" >

EL expressions are not resolved and are treated as strings.

Later, web. xml was changed to

<web-app version="2.4" 

Redeploy, start tomcat, and the EL expression is resolved correctly.

Later, I checked the data in one step and learned that:

This is a new feature of Jsp 2.0:

2) Introducing Expression Language (EL)

A major feature of JSP 2.0 is its support for expression languages (expression language). The JSTL expression language provides easy access to JSP implicit objects and JavaBeans components using tag formats, and the core tags of JSTL provide flow and loop control capabilities. Self-made tags also have the function of custom functions, so basically all the functions that seriptlet can achieve can be replaced by JSP. In JSP 2.0, it is recommended to use EL as much as possible to make JSP more formatted.

In < jsp-property-group > of web. xml, you can control whether one set of JSP uses EL, and in each JSP you can specify whether the JSP uses EL. The isELIgnored attribute in page directive is used to specify whether to ignore. The format is:

<% @ page isELIgnored= "truefalse"% >

If set to true, the expression in JSP is treated as a string. For example, the following expression < p > ${2000% 20}

outputs ${2000% 20} when isELIgnored = "true" and 100 when isELIgnored = "false". The Web container defaults to isELIgnored = "false".

Although JSP 2.0 can make JSP completely use expression language and avoid scriptlet, in actual programming, we should choose the appropriate way according to the functional requirements of the program and the programmer's own conditions. JSP, which uses the expression language, is more convenient and regular, but it will be slow when it is called for the first time because of the need to convert tags; Some programmers are more accustomed to the programming methods before JSP 1.2 because of their better understanding of Java. Therefore, suitable programming methods should be selected according to local conditions in use.

That is to say, the default setting in javaee4 is <% @ page isELIgnored= "false"% >, while the default setting in javaee5 may be <% @ ES90isELIgnored= "true"% >, so in javaee5 we can specify that the EL expression is resolved normally by setting <% @ page isELIgnored= "false"% > on the jsp page.

Related articles: