文章摘要
在使用IDEA开发maven+springMVC项目时,遇到JSP代码中EL表达式未被识别的问题。具体来说,`c:forEach`标签中的`username`和`password`字段无法正确显示,系统提示未加载EL表达式。经过分析,问题与JSP的配置设置有关。
解决方法如下:
1. **检查JSP的`isELIgnored`属性**
在JSP代码的开头添加`isELIgnored`属性,该属性用于控制是否忽略EL表达式。请注意,`isELIgnored`仅在JSP 2.0及以上版本中可用,而早期版本的JSP不支持该属性。
2. **确认Servlet的版本**
使用`web.xml`文件查看所使用的Servlet版本。如果文件中包含`DTD Web Application 2.3`,说明采用的是Servlet 2.3版本,这种情况下默认`isELIgnored`属性的值为`true`,导致EL表达式无法被识别。
3. **调整`web.xml`配置**
如果`isELIgnored`属性的值为`true`,可以通过修改`web.xml`文件中的`isELIgnored`属性来启用EL表达式支持。例如:
```xml
<isELIgnored>true</isELIgnored>
```
修改后需重新部署应用,确保Servlet版本设置正确。
4. **添加JSTL依赖项**
如果上述方法仍无法解决问题,可以在maven项目中手动添加JSTL的依赖项,确保JSTL库能够被正确识别和使用。
通过以上步骤,可以解决JSP代码中EL表达式未被识别的问题,确保JSTL功能正常工作。
在使用IDEA开发maven+springMVC项目时遇到不加载EL表达式的问题,怎么处理呢?下面小编给大家带来了实现代码,一起看看吧
加载如下JSP代码:
<%@ page contentType=”text/html;charset=UTF-8″ language=”java” %>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>
<%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:forEach items=”${userList }” var=”lists”>
<h3>${lists.username }</h3>
<h3>${lists.password }</h3>
</c:forEach>
</body>
</html>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>
<%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:forEach items=”${userList }” var=”lists”>
<h3>${lists.username }</h3>
<h3>${lists.password }</h3>
</c:forEach>
</body>
</html>
显示结果为:
${lists.username }
${lists.password }
${lists.password }
按平常来说引入JSTL包理应执行EL表达式,但却没有…
解决方法:
在JSP开头添加
isELIgnored是指是否忽略EL表达式
isELIgnored 属性JSP 2.0 新引入的属性,在只支持 JSP 1.2 及早期版本的服务器中,使用这项属性是不合法的。这个属性的默认值依赖于 Web 应用所使用的 web.xml 的版本。如果 web.xml 指定 servlet 2.3(对应JSP 1.2)或更早版本,默认值为 true(但变更默认值依旧是合法的,JSP 2.0 兼容的服务器中都允许使用这项属性,不管 web.xml 的版本如何)
查看Servlet版本
打开web.xml文件就可以看到
<!DOCTYPE web-app PUBLIC
“-//Sun Microsystems, Inchttps://www.jb51.net/article//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd” >
“-//Sun Microsystems, Inchttps://www.jb51.net/article//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd” >
按住Ctrl点击链接,到78行左右就可以看到一段注释
<!–
This is the XML DTD for the Servlet 2.3 deployment descriptor.
All Servlet 2.3 deployment descriptors must include a DOCTYPE
of the following form:
<!DOCTYPE web-app PUBLIC
“-//Sun Microsystems, Inchttps://www.jb51.net/article//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”>
–>
This is the XML DTD for the Servlet 2.3 deployment descriptor.
All Servlet 2.3 deployment descriptors must include a DOCTYPE
of the following form:
<!DOCTYPE web-app PUBLIC
“-//Sun Microsystems, Inchttps://www.jb51.net/article//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”>
–>
翻译一下就是
“这是Servlet 2.3部署描述符的XML DTD。所有的Servlet 2.3部署描述符必须包含于下面的DOCTYPE”
很明显这就是Servlet 2.3版本
所以
isELIgnored的属性默认为true…
如果还有问题?
建议在maven dependencies添加引用包(个人感觉这个不是问题,加不加一样…)
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
总结
以上所述是小编给大家介绍的使用IDEA编写jsp时EL表达式不起作用的完美解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:jsp EL表达式详解JSP页面无法识别EL表达式问题解决方案浅谈SpringMVC jsp前台获取参数的方式 EL表达式jsp 开发之struts2中s:select标签的使用JSP中EL表达式用法_动力节点Java学院整理JSP 开发之 releaseSession的实例详解springMVC如何将controller中Model数据传递到jsp页面JSP之EL表达式基础详解
© 版权声明
文章版权归作者所有,未经允许请勿转载。