I'm trying out IntelliJ IDEA 9 for 30 days, and I like what I'm seeing so far. The only glaring problem I have is that the editor seems to have no idea what to do with JSP implicit object methods...
Example 1:
<body>
<% out.println("Hello, World!"); %>
</body>
The editor marks the "println" in this statement as an error and says: Cannot resolve method 'println(java.lang.String)' This syntax is about as basic as you can get, and it works just fine if I deploy it to my app server (Tomcat 7), but IntelliJ insists that there's no such method for the "out" object. It's not just "out", either. It doesn't recognize any implicit object's method...
Example 2:
<body>
<%
String contextRoot = pageContext.getServletContext().getRealPath("");
.
.
.
%>
</body>
In this case, IntelliJ doesn't recognize the getServletContext() method, but it does recognize the getRealPath() method. How weird is that?
What blows me away is that I've scoured the Web for any mention of this problem with IntelliJ 9, and I've come up with zilch. This suggests that maybe I've done something freakish with my setup, but I can't imagine what. Like I said above, it works just fine if I build and deploy anyway; it's just irritating to have my JSP pages filled with false red errors all over 开发者_如何学Cthe place. Kinda defeats the purpose of using an intelligent IDE in the first place.
Anyway, I thought I'd toss this in front of the experts and see if you guys can shed some light on the issue. Any insight would be appreciated!
You'll have this problem with out
, pageContext
and jspContext
because they use classes provided with the JSP api (not the servlet API).
To use them (if you're working with a maven project) add this dependency :
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
</dependency>
If you have the problem with every implicit object (session
, request
, etc.) you should add the servlet api dependency too :
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
You must export (with a checkmark) near each of the
file -> Project structure -> Modules -> Dependencies -> Add
libs you intend to deploy.
If you're having trouble with the session variable being recognized, open the file in IntelliJ. Place the following page directive at the top of your file, and instantly the session variable will be made available and recognized in the IntelliJ editor.
<%@ page session="true" language="java" %>
If you already have the page directive, you can simply add this attribute:
session="true"
精彩评论