Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP called from filter not finding JavaScript file

 
Ernest Kari
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could someone please help me...

I have a JSP that's beeing called by a filter as follows:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
...
RequestDispatcher reqDispatch = request
.getRequestDispatcher("/Desktop/MyJSP.jsp");
reqDispatch.forward(request, response);
...
}

The JSP includes the following lines:
<SCRIPT src="../javascript/Util.js"></SCRIPT><noscript>Javascript is required.</noscript>
<SCRIPT language="JavaScript">getStylesheet(navigator, document);</SCRIPT><noscript>Javascript is required.</noscript>

Now, when the browser is trying to render the page, it generates the following two errors:
Syntax error
Object expected error

The two errors correspond to the two SCRIPT lines above. When I removed the SCRIPT lines the two errors were gone.

The question is why the the Util.js Javascript is not being found by the server?

Please note that I did read the FAQ on how to resolve resource url problems. Unfortunately, the following suggestion from FAQ did not solve the problem:
<script src="${pageContext.request.contextPath}/javascript/Util.js"></script>


Any ideas?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<SCRIPT src="../javascript/Util.js"></SCRIPT>

Never use page-relative addressing in a Java web app.

See the JSP FAQ for info on how to properly format URLs to resources in web applications.
 
Ernest Kari
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did try server relative addressing as I mentioned at the bottom of my previous posting:
<script src="${pageContext.request.contextPath}/javascript/Util.js"></script>

It did NOT solve the problem. What else could cause this issue? Could this have something to do with the JSP being called from the filter? Any other ideas? :roll:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the server-relative address is not correct.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the absolute URL with which you call this JSP page?
What is the absolute URL with which you can call the JS file independently?

Once you know that, you can easily extract the relative URL to the JS file from that.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
more over, i dont see FilterChain.doFilter(request,response) in your fiter class.further, if you want to forward to jsp or servlet you need to mention that .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is forwarding.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic