JSP editing: is it possible to define the contextPath for IntelliJ? ("Cannot resolve directory")

Inside of my app IntelliJ always show the warning "Cannot resolve directory 'js'" (or whatever the path is) for css, js, and images.
For example:
A - <script type="text/javascript" src="http://www.myDomain.com/myContextPath/js/jquery.js"></script>
B - <script type="text/javascript" src="/myContextPath/js/jquery.js"></script>
C - <script type="text/javascript" src="../js/jquery.js"></script>
D - <script type="text/javascript" src="js/jquery.js"></script>

A - <script type="text/javascript" src="http://www.myDomain.com/myContextPath/js/jquery.js"></script>
A - <script type="text/javascript" src="http://www.myDomain.com/myContextPath/js/jquery.js"></script>

2 comments

Sorry I didn't get to finish editing before the form was submitted... (is this form timed)

If my jsp file is mapped to with an action (this is a struts application) and not directly related to a directory ( the action url is always the root of the context path)  and the application is served with the context path of "myContextPath/" there is no way to get both IntelliJ to recognize that my link to jquery.js is correct and to actually have it be correct (that is work).

I can change the path src to be "/js/jquery.js" and IntelliJ will be happy, but that doesn't actually work on the server because the contextPath is eliminated.

Is there  a way to tell intellij to also check an alterantive context path?  Ideally I would like to make the paths relative (like version "D").  I tried adding another "content path" (not context path) in the module, but I get an error message telling me they're not allow to overlap (and it's a huge pain to add every single directory in the root of my web app - and that still excludes the root itself).

0

Don't do includes like that. Not portable across context change and/or across site moves.

Either go the standard jstl core way:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script type="text/javascript" src="<c:url value='/scripts/jquery/jquery-1.3.2.js'/>"></script>

Pro: simple and works without struts.
Con: When there is a session active, a "...&jsessionid=01234..." is sometimes appended to the link and that can mess with caches.


Or you can use the struts url tag:

<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript" src="<s:url includeParams="none" value='/scripts/jquery/jquery-1.3.2.js'/>"></script>

Pro: no jsessionid parameter attached to links.
Con: only works with struts and possibly doesn't work when cookies are disabled (haven't tested if struts adds the jsessionid parameter in this case).

Both ways work with Idea and you get links independent of context and site changes.

Edit:clarification.

0

Please sign in to leave a comment.