You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Twan Kogels <tw...@twansoft.com> on 2003/04/01 14:38:06 UTC

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


RE: Velocity and HttpServletResponse's sendRedirect()

Posted by Twan Kogels <tw...@twansoft.com>.
Tatu,

That is a good tip, i'm go try it out.

Thanks,
Twan

At 08:26 2-4-2003 +0300, you wrote:
>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


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


RE: Velocity and HttpServletResponse's sendRedirect()

Posted by Tatu Vanhanen <ta...@aina.fi>.
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


Re: Velocity and HttpServletResponse's sendRedirect()

Posted by Denis <br...@mac.com>.
On Tuesday, April 1, 2003, at 01:38  pm, Twan Kogels wrote:

> 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.
>

Can you get the current template from the context instead of returning 
null?

-- Denis.


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