许多小伙伴相信像我一样开始使用ItellJ IDEA编译器,用起来非常的爽。
但是使用Maven创建动态Web项目中JSP页面中如下代码会报错,但是运行没问题。当时我非常想解决
代码如下:
<%@ page contentType="text/html; character=GBK" language="java" errorPage="" %>
<html>
<body>
<h2>Hello World!111</h2>
<%
out.print("ok");<span style="white-space:pre"> </span>//这里的print方法会变红,提示错误
%>
</body>
</html>
不止
out
,
pageContext
和
jspContext也会出现同样的问题,原因就是里面使用的是JSP的API(并不是Servlet的API)
所以,在pom.xml文件中加入如下dependency即可。
<dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency>