• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JSP called from filter not finding JavaScript file

 
Greenhorn
Posts: 5
  • 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?

 
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
  • 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
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the server-relative address is not correct.
 
Ranch Hand
Posts: 2458
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • 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
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is forwarding.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic