Project
IntelliJ IDEA
Priority
Normal
Type
Feature
Fix versions
No Fix versions
State
Fixed
Assignee
Dmitry Avdeev
Subsystem
J2EE.JSP
Affected versions
No Affected versions
Fixed in build
108.65  
  • Created by   Taras Tielkes
    6 years ago (06 Nov 2005 20:34)
  • Updated by   root
    2 years ago (17 Jan 2010 20:24)
  • Jira: IDEADEV-7073
    (history, comments)
 
IDEA-30613 Understand variables that resolve to "pageContext.request.contextPath"
0
Issue is visible to: All Users
  The issue is visible to the selected user group only
A common fragment to use in JSP/JSPX is the following variable declaration:

<c:set var="ctx" value="${pageContext.request.contextPath}"/>


Resource patterns in the rest of the HTML/JSP can use the following pattern:

<img src="${ctx}/images/news_pics_10033_1.jpg" alt="test"/>

This alleviates the need to use <c:url> tags.

It would be nice if the JSP editor knew that variables initialized to the "pageContext.request.contextPath" EL expression contain the context path, and can be used to resolve webapp resources.


Issue was resolved
Comments (7)
 
History
 
Linked Issues (?)
 
Taras Tielkes
  Taras Tielkes
10 Nov 2005 00:10
6 years ago
Maxim,

What do you think about this request?
Is the inference required too complex to implement?

Should I use another pattern to get maximum effectiveness out of IDEA?
(I think <c:url> is not very readable if it occurs 40 times on a given page)

The problem is very relevant, as the requirement to not hardcode the context name is very common (in my experience).
Maxim Mossienko
  Maxim Mossienko
18 Nov 2005 19:30
6 years ago
How about just using relative pathes?
As to request, it is not very easy to do.
Taras Tielkes
  Taras Tielkes
18 Nov 2005 23:06
6 years ago
The downsite to using relative paths is that those paths are different from page to page.

The advantage of uning the <c:set var="ctx" value="${pageContext.request.contextPath}"/> pattern is that it is uniform.
Taras Tielkes
  Taras Tielkes
19 Nov 2005 04:41
6 years ago
I've added a RFE to the JSTL specification tracker that is related to this:
https://jstl-spec-public.dev.java.net/issues/show_bug.cgi?id=21
Maxim Mossienko
  Maxim Mossienko
11 Dec 2006 09:40
5 years ago
<img src="#{facesContext.externalContext.requestContextPath}/images/blah.gif"/>
Taras Tielkes
  Taras Tielkes
08 Nov 2007 03:10
4 years ago
Here's a more general description of the problem, and why people use "pageContext.request.contextPath": http://faq.javaranch.com/java/ResourceUrlProblems

To my best knowledge, even as of 2007 it's the only workable solution that has the following desirable properties:
  • works when deploying with different webapp context names (or deploying in root context)
  • is uniform (no need to check paths when moving/cloning JSP files)
  • doesn't make writing an average JSP/JSPX a total chore (like using <c:url> everywhere would do). Declaring it once (using <c:set> on top of page makes all resource references quite concise)

Obviously at the moment quite desirable resolving (and features that depend on proper resolving) is missing when using this pattern.

I can't say how widespread usage of this pattern is, but a quick google session finds a number of people recommending it.
Dmitry Avdeev
  Dmitry Avdeev
22 Jan 2008 19:40
4 years ago
IDEA tries now to resolve starting dynamic fragments (like ${ctx}) to the web module's root