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!
There are 9 jsp implicit objects. These objects are created by the web container that are available to all the jsp pages. The available implicit objects are out, request, config, session, application etc. A list of the 9 implicit objects is given below: For writing any data to the buffer, JSP provides an implicit object named out.
JSP Session implicit object is an instance of javax.servlet.http.HttpSession class.The session object is created for the requesting clients (if any). This variable is only valid for HTTP-based protocol. we can use this object to get, set, and remove an attribute from the session scope.
For writing any data to the buffer, JSP provides an implicit object named out. It is the object of JspWriter. In case of servlet you need to write:
Also, check File > Project Structure > Problems, you may see the problem in there. Even though I've specified the JDK, intelliJ still failed to recognize java imports. The problem was with the caches. Simpli try 'File | Invalidate Caches'. Open the Project Structure, and select a Project SDK.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With