You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Twan Kogels <tw...@twansoft.com> on 2003/03/27 14:21:57 UTC

Re: add http header in VelocityServlet? (SOLUTION)

Hallo,

I've found it after looking at the api docs. VelocityServlet has a method 
"setContentType()". In this method you can set the content type, but also 
add several other headers to the http header. It's a little dirty but i 
works :-)

Best regards,
Twan

At 14:08 27-3-2003 +0100, you wrote:
>Hello,
>
>Is it possible to add a http header to the response object when using 
>VelocityServlet? I searched the archives and found to add http header with 
>the template 
><http://www.mail-archive.com/velocity-dev@jakarta.apache.org/msg06615.html>. 
>But that isn't exactly what i wanted, i want to add a header in the 
>servlet, for example in the handleRequest() methode of VelocityServlet.
>
>I tryed something like :
>
>((HttpServletResponse)ctx.get(VelocityServlet.RESPONSE)).addHeader("header: 
>", "val");
>
>But that didn't work. Am i'm on the wrong path?
>
>Best regards,
>Twan
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


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


Re: add http header in VelocityServlet? (SOLUTION)

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Twan Kogels <tw...@twansoft.com> writes:

> I've found it after looking at the api docs. VelocityServlet has a
> method "setContentType()". In this method you can set the content
> type, but also add several other headers to the http header. It's a
> little dirty but i works :-)

I find it odd that addHeader() didn't work, though I don't think that
you should be including the trailing colon and space like in your
example below.  You can always override Template
handleRequest(HttpServletRequest, HttpServletResponse, Context) if you
want direct access to the response object.  VelocityServlet's
setContentType() method just delegates to the response object anyhow.

    protected void setContentType( HttpServletRequest request,
                                   HttpServletResponse response )
    {
        response.setContentType( defaultContentType );
    }

> At 14:08 27-3-2003 +0100, you wrote:
> >Hello,
> >
> > Is it possible to add a http header to the response object when
> > using VelocityServlet? I searched the archives and found to add http
> > header with the template
> > <http://www.mail-archive.com/velocity-dev@jakarta.apache.org/msg06615.html>. But
> > that isn't exactly what i wanted, i want to add a header in the
> > servlet, for example in the handleRequest() methode of
> > VelocityServlet.
> 
> >
> >I tryed something like :
> >
> > ((HttpServletResponse)ctx.get(VelocityServlet.RESPONSE)).addHeader("header:
> > ", "val");
> 
> >
> >But that didn't work. Am i'm on the wrong path?

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