如果遇到el表達式不生效(原樣輸出問題不被解析)問題,比如${yanggb}被原樣輸出成字符串,通常的原因是servlet3.0默認關閉了el表達式的解析,因此jsp頁面忽視了el標簽,要加入不忽略el表達式的page指令才行。
<%@ page isELIgnored="false" %>
注:EL表達式是不需要引入包的,tomcat自帶servlet的包。
拓展
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標簽中的命名空間來解決。
<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.xml中配置jsp-config標簽。
<jsp-config> <jsp-property-group> <url-pattern>/jsp/* </url-pattern> <el-ignored>true</el-ignored> </jsp-property-group> </jsp-config>
"我等了很久很久,也沒有等到你。"