views:

17

answers:

1

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 the 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!

+2  A: 

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>
Colin Hebert
Thanks for the response, Colin. I'm actually not working with a Maven project. This is just plain old IntelliJ IDEA deploying an exploded war artifact to Tomcat 7. I'm open to using a Maven project as an alternative, but it seems odd that I'd need to just to clean up all the red in the editor...
Syndog
Did you add the application server libs in your project ? In `file` -> `Project structure` -> `Modules` -> `Dependencies` -> `Add`. If you configured tomcat as an application server in IntelliJ you'll be able to add the dependencies.
Colin Hebert
Eureka! Okay, so gotta add the app server libraries to the project dependencies. I didn't realize that these objects were web app specific. So, if I'm deploying to a different app server at some point (JBoss, for instance), I'd have to do the same thing with its libraries? Thanks so much for your help, Colin.
Syndog
You don't really have to do that. This allow to use libs provided by your app server, if you only use servlets and JSP, you won't need to add other deps. But if you want for example use EJB etc. you'll have to add JBoss libs. Anyway, you should have a look at Maven, it will simplify this task for you by using only the dependencies you've defined yourself.
Colin Hebert
Will do. Thanks again!
Syndog