"Can not find declaration to go to" in JSP web resources with relative path Follow
Project problem:
We are trying to make the code cleaner while still supporting deploying the same app into different contexts under Tomcat.
Current solution:
The best solution so far we found is to use the <base href="PATH" /> in the <head> section, and then make all the links inside the html relative to that base path.
The code then would look like:
<head>
<base href="http://mysite.com/qa" />
<link rel="stylesheet" href="css/style.css">
...
</head>
And we are using the same approach for all the other links inside all JSP files.
It works just fine in Tomcat.
Idea problem:
But then we get a problem with navigating to all those relative links in Idea. Whenever we click on such a link we get "Can not find declaration to go to". Changing links to <link rel="stylesheet" href="/css/style.css"> of course works for Idea navigation, but then it doesn't work under Tomcat =)
Question:
Is there any way to make Idea using project Web Resource Directory setting as a prefix to resolve all these relative links? Or if there is any other solution to make navigation working with these relative links.
Thanks,
Roman
Please sign in to leave a comment.
I'd recommend against using <base> here, you might want to try JSTL's <c:url> for proper context-URL rewriting.
Any particular reason against using <base>?
We have been using <c:url> for some time, and then switched to defining a context attribute in the base Servlet class, but anyway, all the links look like:
<link href="${ctx}/css/style.css" rel="stylesheet">
And develoeprs need to remember to add that ${ctx} everywhere, which is easy to miss.
<c:url> will automatically take care of the current context (as your solution with ${ctx} does). Anyway, it's the standard of doing URL-rewrites in JSPs and as such perfectly supported in all IDEs.