You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by William BC Crandall <bc...@earthlink.net> on 2005/05/21 00:30:27 UTC

Accessing images through FrontController Servlet

Hello,

I'm starting a new project, using a FrontController servlet
(http://java.sun.com/j2ee/patterns/FrontController.html),
and am unable to access image files. 

My understanding is that each <img> invokes another call 
to the server/servlet, which, due to the mapping in web.xml,
is channeled through the controller servlet, which rejects
the call because it does not point to a sub-servlet.

How can I access images in webapps/ntrr/images/ ?

My web.xml: 

<web-app>

  <servlet>
    <servlet-name>
      controller
    </servlet-name>
    <servlet-class>
      org.ntrr.core.ControlServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>
      controller
    </servlet-name>
    <url-pattern>
      /*
    </url-pattern>
  </servlet-mapping>
  
</web-app>

I have tried, without success, adding: 

    <init-param>
      <param-name>imageUrl</param-name>
      <param-value>http://localhost:8080/ntrr/images/</param-value>
    </init-param>

The files in webapps/ntrr/images/ ARE accessible from
webapps/ntrr/css/ntrr.css, when called as background 
page images, for example.

Any suggestions welcomed. 

Thanks,

-BC

William BC Crandall
bc.crandall [around] earthlink.net


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Accessing images through FrontController Servlet

Posted by Dakota Jack <da...@gmail.com>.
You are right that a call for an image, or css for that matter, is
another call to the server.  And, this call is really not anything
special, except that it returns a stream.  If you want to get a
response from a URL, then you have to follow the rules in doing this. 
If you instead want to get a response from a protocol, like using a
servlet, then you have different rules.  There is nothing really
magical going on.  Why are you using this "init" business?

On 5/21/05, William BC Crandall <bc...@earthlink.net> wrote:
> Thanks Robert,
> 
> Hard-coding the images works fine, but I'm leery of this,
> as they will of course all need to be changed when the app
> goes up on a public server; changes could be localized, but...
> 
> Is there really no way to declare <img> calls in the web-app
> that would allow images to use relative path names?
> 
> The init-param 'imgURL' sounds like it should allow this,
> but I'm not familiar with it.
> 
> Thanks for your suggestion, which gets things moving again.
> Thanks too for the pointer to Ethereal; looks like a useful tool.
> 
> Best,
> 
> -BC
> 
> William BC Crandall
> bc.crandall [around] earthlink.net
> 
> 
> 
> ----- Original Message -----
> From: "Robert r. Sanders" <ro...@ipov.net>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: 20 May 2005 8:36 PM
> Subject: Re: Accessing images through FrontController Servlet
> 
> 
> > Do you have any logs of what's going on?  Also, make sure the pages are
> > using the <c:url /> tag (or equivalent), as the image paths need to be
> > relative to the url that the client browser see - should be able to hard
> > code the path to be /ntrr/images/whatever.jpg
> >
> > To check for bad paths  first view page source from your browser, then
> > you can get the image urls and see if they map to the correct path.
> > There are also some nice tools that you can run to see what's going on,
> > for instance the "Live Headers" extension for Firefox, or Ethereal for a
> > more general solution
> >
> > William BC Crandall wrote:
> >
> > >Hello,
> > >
> > >I'm starting a new project, using a FrontController servlet
> > >(http://java.sun.com/j2ee/patterns/FrontController.html),
> > >and am unable to access image files.
> > >
> > >My understanding is that each <img> invokes another call
> > >to the server/servlet, which, due to the mapping in web.xml,
> > >is channeled through the controller servlet, which rejects
> > >the call because it does not point to a sub-servlet.
> > >
> > >How can I access images in webapps/ntrr/images/ ?
> > >
> > >My web.xml:
> > >
> > ><web-app>
> > >
> > >  <servlet>
> > >    <servlet-name>
> > >      controller
> > >    </servlet-name>
> > >    <servlet-class>
> > >      org.ntrr.core.ControlServlet
> > >    </servlet-class>
> > >  </servlet>
> > >
> > >  <servlet-mapping>
> > >    <servlet-name>
> > >      controller
> > >    </servlet-name>
> > >    <url-pattern>
> > >      /*
> > >    </url-pattern>
> > >  </servlet-mapping>
> > >
> > ></web-app>
> > >
> > >I have tried, without success, adding:
> > >
> > >    <init-param>
> > >      <param-name>imageUrl</param-name>
> > >      <param-value>http://localhost:8080/ntrr/images/</param-value>
> > >    </init-param>
> > >
> > >The files in webapps/ntrr/images/ ARE accessible from
> > >webapps/ntrr/css/ntrr.css, when called as background
> > >page images, for example.
> > >
> > >Any suggestions welcomed.
> > >
> > >Thanks,
> > >
> > >-BC
> > >
> > >William BC Crandall
> > >bc.crandall [around] earthlink.net
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > >
> > >
> > >
> >
> > --
> >     Robert r. Sanders
> >     Chief Technologist
> >     iPOV
> >     (334) 821-5412
> >     www.ipov.net
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


-- 
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Accessing images through FrontController Servlet

Posted by William BC Crandall <bc...@earthlink.net>.
Thanks Robert, 

Hard-coding the images works fine, but I'm leery of this, 
as they will of course all need to be changed when the app 
goes up on a public server; changes could be localized, but... 

Is there really no way to declare <img> calls in the web-app 
that would allow images to use relative path names? 

The init-param 'imgURL' sounds like it should allow this, 
but I'm not familiar with it.

Thanks for your suggestion, which gets things moving again. 
Thanks too for the pointer to Ethereal; looks like a useful tool.

Best,

-BC

William BC Crandall
bc.crandall [around] earthlink.net



----- Original Message ----- 
From: "Robert r. Sanders" <ro...@ipov.net>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: 20 May 2005 8:36 PM
Subject: Re: Accessing images through FrontController Servlet


> Do you have any logs of what's going on?  Also, make sure the pages are 
> using the <c:url /> tag (or equivalent), as the image paths need to be 
> relative to the url that the client browser see - should be able to hard 
> code the path to be /ntrr/images/whatever.jpg
> 
> To check for bad paths  first view page source from your browser, then 
> you can get the image urls and see if they map to the correct path.  
> There are also some nice tools that you can run to see what's going on, 
> for instance the "Live Headers" extension for Firefox, or Ethereal for a 
> more general solution
> 
> William BC Crandall wrote:
> 
> >Hello,
> >
> >I'm starting a new project, using a FrontController servlet
> >(http://java.sun.com/j2ee/patterns/FrontController.html),
> >and am unable to access image files. 
> >
> >My understanding is that each <img> invokes another call 
> >to the server/servlet, which, due to the mapping in web.xml,
> >is channeled through the controller servlet, which rejects
> >the call because it does not point to a sub-servlet.
> >
> >How can I access images in webapps/ntrr/images/ ?
> >
> >My web.xml: 
> >
> ><web-app>
> >
> >  <servlet>
> >    <servlet-name>
> >      controller
> >    </servlet-name>
> >    <servlet-class>
> >      org.ntrr.core.ControlServlet
> >    </servlet-class>
> >  </servlet>
> >
> >  <servlet-mapping>
> >    <servlet-name>
> >      controller
> >    </servlet-name>
> >    <url-pattern>
> >      /*
> >    </url-pattern>
> >  </servlet-mapping>
> >  
> ></web-app>
> >
> >I have tried, without success, adding: 
> >
> >    <init-param>
> >      <param-name>imageUrl</param-name>
> >      <param-value>http://localhost:8080/ntrr/images/</param-value>
> >    </init-param>
> >
> >The files in webapps/ntrr/images/ ARE accessible from
> >webapps/ntrr/css/ntrr.css, when called as background 
> >page images, for example.
> >
> >Any suggestions welcomed. 
> >
> >Thanks,
> >
> >-BC
> >
> >William BC Crandall
> >bc.crandall [around] earthlink.net
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >  
> >
> 
> -- 
>     Robert r. Sanders
>     Chief Technologist
>     iPOV
>     (334) 821-5412
>     www.ipov.net
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Accessing images through FrontController Servlet

Posted by "Robert r. Sanders" <ro...@ipov.net>.
Do you have any logs of what's going on?  Also, make sure the pages are 
using the <c:url /> tag (or equivalent), as the image paths need to be 
relative to the url that the client browser see - should be able to hard 
code the path to be /ntrr/images/whatever.jpg

To check for bad paths  first view page source from your browser, then 
you can get the image urls and see if they map to the correct path.  
There are also some nice tools that you can run to see what's going on, 
for instance the "Live Headers" extension for Firefox, or Ethereal for a 
more general solution

William BC Crandall wrote:

>Hello,
>
>I'm starting a new project, using a FrontController servlet
>(http://java.sun.com/j2ee/patterns/FrontController.html),
>and am unable to access image files. 
>
>My understanding is that each <img> invokes another call 
>to the server/servlet, which, due to the mapping in web.xml,
>is channeled through the controller servlet, which rejects
>the call because it does not point to a sub-servlet.
>
>How can I access images in webapps/ntrr/images/ ?
>
>My web.xml: 
>
><web-app>
>
>  <servlet>
>    <servlet-name>
>      controller
>    </servlet-name>
>    <servlet-class>
>      org.ntrr.core.ControlServlet
>    </servlet-class>
>  </servlet>
>
>  <servlet-mapping>
>    <servlet-name>
>      controller
>    </servlet-name>
>    <url-pattern>
>      /*
>    </url-pattern>
>  </servlet-mapping>
>  
></web-app>
>
>I have tried, without success, adding: 
>
>    <init-param>
>      <param-name>imageUrl</param-name>
>      <param-value>http://localhost:8080/ntrr/images/</param-value>
>    </init-param>
>
>The files in webapps/ntrr/images/ ARE accessible from
>webapps/ntrr/css/ntrr.css, when called as background 
>page images, for example.
>
>Any suggestions welcomed. 
>
>Thanks,
>
>-BC
>
>William BC Crandall
>bc.crandall [around] earthlink.net
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>  
>

-- 
    Robert r. Sanders
    Chief Technologist
    iPOV
    (334) 821-5412
    www.ipov.net