Resource configuration problems on servlets (images, css, javascript)

2006-11-28 Thread Pascal Guy

Hi all,
I'm a bit new to servlet programming so i'll be as clear as i can.
I'm developing a small web application to test servlets in a project at 
school
The project is fairly simple we a jsp pages that POST requests to a 
central servlet that controls the flow of the application
My partner codded the jsp pages (which include css, javascript and 
images) everything working on his side as far as the pages displaying 
the images and the javascipt functionality


The problem comes when we integrate to post the request to my controller
The controller works fine but the resources are not working (css, images 
and javascript)


the configuration is simple

servlet
   servlet-namecontroller/servlet-name
   servlet-classorg.test.controller.Controller/servlet-class
   init-param
   param-namedebug/param-name
   param-value0/param-value
   /init-param
   init-param
   param-namelistings/param-name
   param-valuefalse/param-value
   /init-param
   load-on-startup1/load-on-startup
   /servlet

   servlet-mapping
   servlet-namecontroller/servlet-name
   url-pattern/controller/url-pattern
   /servlet-mapping
  
the images have the right path to access the resources when i check the 
properties


When i debug the application i can see multiple request when i acces the 
login page (or any other page for that matter)
as if the request to get the images (or resources) were handled by my 
servlet and my servlet as it's coded does'nt recognize that type of 
event (each request has to have an event type)


The controller works fine but even with multiple changes to my 
configuration i can't get the resources to work properly.


Do i need to map the resource types to something so it bypasses my 
servlet (and not be treated as a request)


I can't figure this out, though i've tried many setups.

Thanks anybody.

--
Pascal


-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Resource configuration problems on servlets (images, css, javascript)

2006-11-28 Thread Kristian Rink

Hi;

Pascal Guy schrieb:
 The problem comes when we integrate to post the request to my controller
 The controller works fine but the resources are not working (css, images
 and javascript)


I am not sure to understand your problem right, but:

servlet-mapping
servlet-namecontroller/servlet-name
url-pattern/controller/url-pattern
/servlet-mapping
[...]
 Do i need to map the resource types to something so it bypasses my
 servlet (and not be treated as a request)


There _will_ be a request for each and every static component (i.e.
image, css, js file, whatever) to be loaded from the server - but
indeed, you shouldn't have your controller taking care of that.

How are you referring to images and js from within your code? You should
be sure to use absolute URLS (i.e. /images/logo.png instead of
images/logo.png), otherwise you might end up with your server
searching for the content in a place where it's not supposed to be found
 (i.e. /servlet-context/controller/images/logo.png). If you keep
that in mind, chances are you won't have to do much configuration work
in your web.xml but simply ensure that folders containing static things
are somewhere out of the way of your servlet mappings.

Hope this helps, good luck to you!
Cheers,
Kris

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Resource configuration problems on servlets (images, css, javascript)

2006-11-28 Thread Pascal Guy

Hi,

i have tried the absolute path

   img border=0 src=/images/topImage.gif width=300 height=15

which renders to

   http://localhost:8080/images/topImage.gif   (which i know is not 
the good path)


but in the jsp we access the resource like this

   img border=0 src=%=request.getContextPath() + 
/images/topImage.gif% width=300 height=15


which renders to

   http://localhost:8080/TEST/images/topImage.gif(where TEST is my 
application)


this worked fine for my partner on his sample controller servlet but did 
not have any server side code except the jsp
also when i look at the deployed application in Eclipse it gives me this 
path


C:\Program 
Files\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\_webapps\TEST\images_


so the path is good (i think) when i look at the properties of the 
images on the html page


you said all the resources should make a request to the server but what 
i can't understand is why is it being caught and treated by my servlet


that's why i assumed there was some configuration problem so these 
request would be treated by a default servlet of some sort and not my 
servlet
which is configured to have event types for every request and treats 
these requests for resources as unknown events


my lack of knowledge in servlets is probably misleading me here


Pascal



Kristian Rink wrote:

Hi;

Pascal Guy schrieb:
  

The problem comes when we integrate to post the request to my controller
The controller works fine but the resources are not working (css, images
and javascript)




I am not sure to understand your problem right, but:

  

   servlet-mapping
   servlet-namecontroller/servlet-name
   url-pattern/controller/url-pattern
   /servlet-mapping


[...]
  

Do i need to map the resource types to something so it bypasses my
servlet (and not be treated as a request)




There _will_ be a request for each and every static component (i.e.
image, css, js file, whatever) to be loaded from the server - but
indeed, you shouldn't have your controller taking care of that.

How are you referring to images and js from within your code? You should
be sure to use absolute URLS (i.e. /images/logo.png instead of
images/logo.png), otherwise you might end up with your server
searching for the content in a place where it's not supposed to be found
 (i.e. /servlet-context/controller/images/logo.png). If you keep
that in mind, chances are you won't have to do much configuration work
in your web.xml but simply ensure that folders containing static things
are somewhere out of the way of your servlet mappings.

Hope this helps, good luck to you!
Cheers,
Kris

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


  


-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]