users@jersey.java.net

Re: [Jersey] Static references from JSP

From: jstrachan <james.strachan_at_gmail.com>
Date: Mon, 26 Jan 2009 10:34:50 -0800 (PST)

Paul Sandoz wrote:
>
>
> On Sep 2, 2008, at 8:46 AM, Paul Sandoz wrote:
>
>> On Sep 2, 2008, at 8:13 AM, Craig McClanahan wrote:
>>
>>> Paul Sandoz wrote:
>>>> Julio Faerman wrote:
>>>>> I have tried to write out the resource, but this is troublesome
>>>>> as the
>>>>> resource is not on the classpath. I think there is a method to
>>>>> get web
>>>>> resources in servlet 2.5,
>>>>
>>>> You need to use methods on the ServletContext.
>>>>
>>>>
>>>>> but i also think that the forward should
>>>>> work.
>>>>
>>>> I cannot get it to :-( it works for JSPs, but not for "static"
>>>> stuff like HTML and images, perhaps it is bug in the GF servlet
>>>> implementation i am using?
>>>>
>>>>
>>> What servlet mappings do you have defined?
>>>
>>
>> "/" or "/*". I want to avoid a URL for the main application like:
>>
>> http://host:80/<deployment base>/<jersey base>
>>
>> and exposing out the other resources (static or JSP pages) explicitly.
>>
>> I can forward to JSPs but not to static content.
>>
>
> After more investigation
>
> - If the URL pattern is "/" then i can forward to JSPs but not to
> static content.
>
> - If the URL pattern is "/*" then i cannot forward to JSPs nor static
> content.
>

I guess (as Craig says) folks can just map the Jersey servlet to those URL
patterns which folks know should only contain JAX-RS or implicit views.
e.g. /foo and /bar then leave /css/* /images/* and /js/* to be served up by
the Servlet engines default servlet. Though that is a bit icky.

Its such a shame in the Servlet spec you can't kinda map specific URIs to
being static content. e.g. being able to say that /images/* /css/* and /js/*
are static content so don't map them to Jersey's servlet would be great.

Its a shame there's not a 'not' in the servlet mapping. I wonder if the
servlet spec should be updated to allow a true regex to be used for the URL
mapping to make this kinda stuff easier?

Basically if folks use JAX-RS as a web framework like
Struts/SpringMVC/Stripes et al - being able to easily serve up static
content for CSS/JavaScript/images (or regular JSP views outside of the
JAX-RS stuff) is gonna be key. So I think we need to figure out some best
practice for either

(i) only mapping Jersey to specific URI patterns or
(ii) telling Jersey to exclude URIs and delegate to the default servlet

Anyone else got any ideas of how to come up with a more generic best
practice for mixing and matching Jersey with static content & JSPs?
-- 
View this message in context: http://n2.nabble.com/Static-references-from-JSP-tp794843p2219723.html
Sent from the Jersey mailing list archive at Nabble.com.