users@jersey.java.net

Re: [Jersey] forwarding to another URL

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 15 May 2009 11:06:20 +0200

On May 14, 2009, at 3:25 PM, Hubert Le Van Gong wrote:

> Maybe an obvious one: how do I go about forwarding the request to
> another URL (like a jsp page)?

I presume you want to forward to something within the same app to
avoid multiple HTTP requests?

If it is a JSP page then your resource method can return a Viewable
instance and refer to the absolute path of the JSP page in the Web app:

https://jersey.dev.java.net/nonav/apidocs/1.0.3-SNAPSHOT/jersey/com/sun/jersey/api/view/Viewable.html

For example:

   @GET
   public Viewable get() {
     return new Viewable("/myJspPage.jsp", "SomeModelInformation");
   }



> I want to avoid using a redirect (i.e. SeeOther with the Response
> builder).
>
> Is RequestDispatcher() meant for this?
> So something like:
>
> RequestDispatcher reqdisp;
> reqdisp.dispatch(jsp_location_uri, context);
>

Are you referring to the servlet ReqestDispatcher? if so Jersey will
use that when processing the Viewable instance for JSP pages.

Paul.

>
> Cheers,
> Hubert
>
>
>
> --
> Hubert A. Le Van Gong
> Identity Architect
> Sun microsystems, Inc.
>
>
> 17 Rue Duprey
> Grenoble, 38000
> France
>
> --------------------------------------------------
> email: hubert.levangong_at_sun.COM
> tel:+33 4 7663 0935
> blog: http://blog.levangong.com/
>
> N 45 12.011'
> W 005 44.217'
>