users@jersey.java.net

Re: [Jersey] Static references from JSP

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 01 Sep 2008 09:17:14 +0200

Hi Julio,

Could you send me an example?

> I am using implicit JSP Viewables (just like bookstore sample), but i
> don't know how can i reference a static resource (images, styles,
> scripts) from the page.
>

Does the following describe your problem?

If i have a resource:

   com.foo.Foo

and an index.jsp in:

   com/foo/Foo/index.jsp

and there is an image at the location:

   com/foo/Foo/image.png

how does "index.jsp" reference "image.png".


> I am trying a method that fowards to the requested resource, but
> servletContext.getRequestDispatcher().forward() is failling because
> the injected HttpServletRequest and Response are null. Is there a
> better way to do this?
>

If you are using Servlet you should be able to do:

   @Context HttpServletRequest req;

   @Context HttpServletRequest res;

as fields or method parameters.

You should be able to reference a static page using a Viewable. Just
return something like this:

   // Absolute reference
   return new Viewable("/static.png", null);

   // Reference relative to the resource class or a super class
   return new Viewable("static.png", null);

Paul.