今天在IDEA創建web項目之后發現無法使用EL和JSTL,
一、如果JSP中無法自動提示EL表達式,比如${pageContext.request.contextPath},可在pom.xml的<dependencies>標簽中插入以下代碼
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
下面是EL和JSTL的坐標,不用pom.xml中設置,由上面的依賴傳遞:
<!--EL和JSTL--> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
二、如果無法使用EL表達式
方法1:更改web.xml的web-app標簽中的命名空間,可改成如下
<?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>
方法2:在jsp頁面開頭添加<%@ page isELIgnored="false"%>
