users@glassfish.java.net

Re: Best practice to automatically forward to another directory/Web app?

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Thu, 08 Mar 2007 11:08:41 -0500

Hi,

glassfish_at_javadesktop.org wrote:
> I have one Web app (Web app A) set up as the default module at /. I want to redirect all requests to / to another Web app (Web app B) at /mywebapp. I could tell the index.html on A to do a simple redirect to /mywebapp, but I actually want to have all kinds of page requests to go to /mywebapp, such as /hello.jsp -> /mywebapp/hello.jsp. Is there any easy way to do that in Glassfish 2?
>

The simplest way is for you to write a filter that intercept all request:

> <filter>
> <display-name>RedirectFilter</display-name>
> <filter-name>RedirectFilter</filter-name>
> <filter-class>org.RedirectFilter</filter-class>
> </filter>
> <filter-mapping>
> <filter-name>RedirectFilter</filter-name>
> <url-pattern>/*</url-pattern>
> <dispatcher>REQUEST</dispatcher>
> <dispatcher>INCLUDE</dispatcher>
> <dispatcher>FORWARD</dispatcher>
> <dispatcher>ERROR</dispatcher>
> </filter-mapping>

Then in your Filter you can decide to either user a RequestDispatcher or
use the HttpServletResponse.sendRedirect(..). I would recommend the
HttpServletResponse.sendRedirect(..) because you can not only redirect
locally but to any url. Using google I've found the following example[1];

Hope that help.

-- Jeanfrancois

[1] http://www.zlatkovic.com/httpredirectfilter.en.html


> dailysun
> [Message sent by forum member 'dailysun' (dailysun)]
>
> http://forums.java.net/jive/thread.jspa?messageID=206868
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>