velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tatu Vanhanen" <tatu.vanha...@aina.fi>
Subject RE: Velocity and HttpServletResponse's sendRedirect()
Date Wed, 02 Apr 2003 05:26:46 GMT
Hi
If you override the "handleRequest( HttpServletRequest request,
HttpServletResponse response, Context ctx )" instead of "handleRequest(
Context ctx )", you are allowed to return null and handle the request
completely in there, so no Exceptions thrown.

The meaning of the handleRequest methods are the same, expect that the
version with also request and response as parameters allowes you to handle
the request completely by returning null as a template.

I hope this is what you need.

- Tatu V.

-----Original Message-----
From: Twan Kogels [mailto:twan@twansoft.com]
Sent: 1. huhtikuuta 2003 15:38
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