您的位置:首页 > Web前端 > JavaScript

JSP页面EL表达式不解析

2016-11-09 20:34 417 查看
现象如下:



经过查阅资料,有四种情况下EL表达式是无法正确别解析的,

分别是:

Application server in question doesn’t support JSP 2.0. (应用服务器不支持JSP2.0)

The web.xml is not declared as Servlet 2.4 or higher. (web.xml中servlet版本没有声明在2.4以上)

The @page is configured with isELIgnored=true. (页面上配置了<%@ page isELIgnored=”true” %> )

The web.xml is configured with true in . (web.xml中显式地配置了忽略EL表达式)

最终发现我的web.xml中声明的servlet版本是2.3,所以默认是不自动解析EL表达式的。

而我的web.xml这样是使用了maven-archetype-webapp创建的缘故。

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>

<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</w
4000
eb-app>


只要更改成如下即可, 版本最好是你项目中使用的JSP版本,

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
...
</web-app>


总结一下:页面无法解析EL表达式是因为web.xml中JSP版本在2.4以下,而我在项目中使用的是JSP3.0,原因在于工程是通过maven-archetype-webapp创建的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jsp spring4