wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP called from filter not finding JavaScript file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP called from filter not finding JavaScript file" Watch "JSP called from filter not finding JavaScript file" New topic
Author

JSP called from filter not finding JavaScript file

Ernest Kari
Greenhorn

Joined: Jan 10, 2009
Posts: 5
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

Joined: Jan 10, 2002
Posts: 60082
    
  65

<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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ernest Kari
Greenhorn

Joined: Jan 10, 2009
Posts: 5
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

Joined: Jan 10, 2002
Posts: 60082
    
  65

Then the server-relative address is not correct.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 10, 2002
Posts: 60082
    
  65

The code is forwarding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP called from filter not finding JavaScript file
 
Similar Threads
Integerating DWR with security logic
DWR unable to include js file
Can't access dwr.util in Jspx page of Spring MVC application
Can't include .js file on jsp page controlled by front controller servlet
ServletException: bean not found within scope