在学习javaweb过程中的某天,突然遇到了jsp文件中的el表达式失效的问题,表达式直接就显示在了页面上,或者该控制显示出来的直接没有了不显示
在网上查了各前辈的笔记后,我的解决方法为,在jsp页面的头部加上不忽略EL的指令
原因是servlet3.0默认关闭了el表达式的解析,因此jsp页面忽视了el标签
拓展学习笔记:
1.如果JSP中无法自动提示EL表达式的解决方法,在maven的pom.xml中加入如下代码。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
2.如果JSP中EL表达式不起作用,原样输出,除了最上面的解决方案外,可以更改web.xml的web-app标签中的命名空间来解决。目前更新到4.0了
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
或者试试那个能行
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
另外还需要在web.xml中配置jsp-config标签。
<jsp-config>
<jsp-property-group>
<url-pattern>/jsp/* </url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>
参考文章: