0

I'm working with a team of devs using Netbeans, but unfortunately the code they're working on has been stuck using ancient tech for far too long now. In some recent research, I discovered Java's "Expression Language" and I've been converting one of our webapps to use this for building stylesheet and script file URL links rather than the current "relative path" idea.

For example, we have one or two .jsp files in the webapp root, and others in a subfolder, all of which are now using:

<link href="${pageContext.servletContext.contextPath}/assets/css/stylesheet.css" rel="stylesheet" type="text/css"/>

<script src="${pageContext.servletContext.contextPath}/assets/js/script.js" type="text/JavaScript"></script>

Netbeans 8.0.1 doesn't seem to pick up classes from the stylesheet; so even though it runs correctly in a browser, my test project is now riddled with "class not found" warning messages.

So my main question (using Java 6 or 7): is this a good way to do it or should I look for other options? Otherwise, is this simply an IDE bug that's got me worried for no reason..?

For the sake of clarity, I'm only just starting to drag them out of the Java 6 world.. I'm honestly not sure why, but until recently they've been against the idea of relying on application frameworks and libraries, opting to write everything themselves from scratch; so this is an attempt to "fix" a few glaring issues is our current apps to give us a chance to rewrite them using more modern technologies.

  • 1
    The technical question is duplicated here: http://stackoverflow.com/questions/3655316/browser-cant-access-find-relative-resources-like-css-images-and-links-when-cal/ As to the tooling problem, upgrade Netbeans and then refresh. – BalusC Dec 17 '15 at 08:06
  • @BalusC, thanks for the link, I don't think that question came up in my search earlier. I've just updated NB to 8.1 (latest stable at the moment) and I still get the same IDE behaviour ([screenie here](https://goo.gl/photos/8k7nVHnhXUNBaoGEA)). I'm more curious about the URL itself though; based on your answer in the linked question, could I assume using either `${...}` or `` for loading files is logical move then? –  Dec 17 '15 at 10:40
  • Then it's just a tooling problem. – BalusC Dec 17 '15 at 10:43

1 Answers1

0

After checking the link provided by BalusC in the question comments, some other reading online, and opening my test project in IntelliJ IDEA 15 (which detects the CSS classes correctly); I'm quite satisfied that there are no funny issues with using ${pageContext.servletContext.contextPath} to prefix all my URL attributes.

I cannot make use of the HTML <base> tag since we need to maintain support for IE8 as well.

@BalusC, thanks for the link, that helps clear up a couple minor questions that I had. :)

  • `` works just fine in IE8 and lower. You only need to make sure you close the tag. – BalusC Dec 17 '15 at 11:55
  • Strange, it doesn't work in my tests on IE8 regardless of how I use it... But either way, my main query here was resolved, so I'm happy. :) –  Dec 17 '15 at 12:47
  • Base must be an absolute URL, not relative URL. – BalusC Dec 17 '15 at 12:52