You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Victor Batista <vb...@present-technologies.com> on 2003/05/23 13:58:19 UTC

How to Redirect/Forward from a Generator.

Helllo,
	I am developing a generator which needs to Forward/Redirect the 
user to other locations. How can I achieve this on the Java code (not on 
the sitemap.xmap)?

	
	How can I convert the Cocoon environment classes
			org.apache.cocoon.environment.Context;
			org.apache.cocoon.environment.Request;
			org.apache.cocoon.environment.Response;

	to the standard servlet ones:
			javax.servlet.http.HttpServletRequest;
			.....


	Any help would be welcome.
	Thanks in advance,
		Victor Batista


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: How to Redirect/Forward from a Generator.

Posted by Martin Holz <ho...@fiz-chemie.de>.
Victor Batista <vb...@present-technologies.com> writes:

> 	I am developing a generator which needs to Forward/Redirect the 
> user to other locations. How can I achieve this on the Java code (not on 
> the sitemap.xmap)?
> 
> 	
> 	How can I convert the Cocoon environment classes
> 			org.apache.cocoon.environment.Context;
> 			org.apache.cocoon.environment.Request;
> 			org.apache.cocoon.environment.Response;
> 
> 	to the standard servlet ones:
> 			javax.servlet.http.HttpServletRequest;
> 			.....

You want do do a external redirect (sending 301 or 307 back to the browser)?
You can't access javax.servlet.http.HttpServletRequest directly,
but the cocoon class has all methods you need.

public class MyGenerator extends AbstractGenerator {
  public void generate(..) {
        Response res = (org.apache.cocoon.environment.http.HttpResponse)
                 org.apache.cocoon.environment.ObjectModelHelper.getResponse(super.objectModel);
        res.sendRedirect(location); 

      // generate human friendly html message
      ...
  }
} 
Of course the class cast means, that you can't use the generator in cli mode. 


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org