velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Campbell, Justin" <jcampb...@profilesys.com>
Subject RE: Velocity and HttpServletResponse's sendRedirect()
Date Tue, 01 Apr 2003 17:12:54 GMT
Twan -

	I ran into a similar problem using a custom web framework on a
project over here. We decided to take the approach of throwing an exception
(e.g. "RequestRedirectedException"). For the sake of convenience, we made
this extend RuntimeException. We then created a forwarding method that would
handle the redirect and then throw the exception. This exception would then
be allowed to pass up to the point where where handleRequest() is called and
the Template is expected to be returned. You can then take care of any
special handling/cleanup there.

So far, we haven't found any real issues with this approach.

Hope this helps, and good luck.

- Justin

-----Original Message-----
From: Twan Kogels [mailto:twan@twansoft.com]
Sent: Tuesday, April 01, 2003 7:38 AM
To: velocity-user@jakarta.apache.org
Subject: Velocity and HttpServletResponse's sendRedirect()


Hi all,

I have a problem with Velocity and HttpServletResponse's sendRedirect() 
methode.
For example: I've got a servlet which extends from VelocityServlet. This 
servlet overrides the "handleRequest()" methode of VelocityServlet which is 
defined as:
public Template handleRequest( Context ctx )

The following part of code will illustrate the problem:

public Template handleRequest( Context ctx ){
	Template t=null;
	if(go==true){
		response.sendRedirect("controller?action=go");
	}
	else{
		t=new Command(); //this methode returns a Template object.
	}
	return t;
}

When go==true it calls sendRedirect(), then t=null, this means that when 
go==true, handleRequest() will return null. Returning null results in a 
stacktrace, cause handleRequest() should return a Template.

I now make use of a dummy Template object:

	if(go==true){
		response.sendRedirect("controller?action=go");
		t=new DummyTemplate();
	}

This dummy Template is a empty template, just to avoid returning null and 
getting a stacktrace.

I'm wondering can this be solved in a better way?

Best regards,
Twan


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message