• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Peculiar problem with js and css file

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My JSP is submitting a form to servlet and servlet after processing the date and storing it into session forwards the request to the same JSP. The JSP onload checks that if value of particular variable is true, it closes itself. The JSP includes a javascript and .css file. The problem is when the request is forwarded to the JSP, i receieve following error in my tomcat console (Am using tomcat integrated in JBoss 3.2.5). But these errors are displayed when i first open this JSP from a link

2005-08-24 18:18:32,540 INFO [org.jboss.web.localhost.Engine] StandardContext[/workflow]Marking servlet org.apache.catalina.INVOKER.javascript.js as unavailable
2005-08-24 18:18:32,540 ERROR [org.jboss.web.localhost.Engine] StandardContext[/workflow]Error loading org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader@4ae19a javascript.js
java.lang.ClassNotFoundException: javascript.js
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:954)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:687)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:369)
at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)

Any idea what could be the reason of the above exception?

Thanks,
Kapil
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for typing mistake. The error is not displayed when the JSP is loaded for the first time from a link
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java.lang.ClassNotFoundException: javascript.js


It looks like your servlet is not configured correctly, or the URL you are submitting the page to is not correct.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are probably using relative references to the js and css resources. Bad idea.
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Out of curiosity, why are you using includes for the .css and .js files instead of the standard HTML references like:

<LINK rel="stylesheet" type="text/css" href="css/main.css"/>
<script type="text/javascript" src="js/main.js"></script>

-Yuriy
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When he said "include" I assumed he meant using those mechanisms. It would be odd indeed to use a JSP include for such resources.
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, am using the standard HTML reference as Yuriy has mentioned. MY css and js files are in same directory as the JSP so I am refering them directly without giving the full path from the context. What i cant understand is why tomcat is treating .js and .css files as servlets?
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could provide the code which do this exception?
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JSP code snippet is following

The error comes after rediection to JSP page before it closes
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if it helps, but try it:
in body tag should be OnLoad
In function onLoading you are missing closing bracket.
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote <body onLod> because the site doesnot allow onload to be written while uploading code. I forgot to add closing bracked while pasting code. Actually, its a huge JSP thats why I added the relevant code. The error messages come even If I only use the given code snippet for JSP.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the java class which is generated from this JSP. There you should see what's happened whith javascript.js .
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The generated code is following
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everything looks fine.
I'm sorry, I have no other ideas
[ August 25, 2005: Message edited by: David Ulicny ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to take a look at the generated servlet code to see what the JSP compiler has actually done with your code.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Things to check and/or show us:

1) What does the actual HTML look like?

2) What does javascript.js do?

3) What does your servlet configuration and mapping look like?

4) How is the form submitted? The action does not correspond to the class shown in your stack trace, and the form does not contain any fields; is that intentional?
[ August 25, 2005: Message edited by: Ulf Dittmer ]
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The js file contains some utility functions common to my application. The screen is a popup window and its objective is to submit a form to a servlet and after successful completion, the form closes itself. The form is not submitted if I write window.close just after submitting, thats why i redirect the request back to same jsp which checks that the request is forwarded from a servlet and closes itself.
I found that if i use sendRedirect instead of requestDispatcher.forward in servlet, there is no error in tomcat but that doesn't solve my purpose
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that since you're forwarding and not redirecting, the browser thinks you are still in the servlet directory. For example, in the page showing you are submitting to

/workflow/servlet/com.myapp.initiator.jsp.helper.RecurrenceServlet

If that servlet forwards to a JSP, then any relative references in the JSP will be relative to the mapped location of the servlet, that is a link to "javascript.js" will actually be a link to "<context>/workflow/servlet/javascript.js". To link to the a javascript file inside the Initiator directory you'd have to have use "../../Initiator/javascript.js". Inother words you must link as though your JSP page was in the same location that the servlet was mapped to.

A better way would probably be to use request.getContextPath() to get the root of the application:

<link rel="stylesheet" href="<%=request.getContextPath()%>/Initiator/Initiator.css" type="text/css"/>

scriptless version:

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

-Yuriy
[ August 26, 2005: Message edited by: Yuriy Zilbergleyt ]
 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks yuriy,U hit the bull's eye.
Its working fine now. Thanks once again.
Kapil
reply
    Bookmark Topic Watch Topic
  • New Topic