velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garey Mills <>
Subject Re: Problem with referencing a stylesheet from an XML document generated by a Velocity template
Date Mon, 11 Jun 2007 22:22:57 GMT
Nathan -

    I am now getting the correct content type, but the stylesheet is not 
being applied.

    I have a web application that uses VVS. I have templates that output 
either XML or HTML depending on some conditions. When I output XML, I 
include a reference to an XSL stylesheet. The stylesheet is not being 
applied. When I save the XML output, put it back on the server and 
access it again, the stylesheet is applied. You suggested that the 
problem was that the content type was not set correctly, and indeed, the 
content type was 'text/html'. I extended the VVS so that I can signal 
the VVS as to the content type I wish set in the response from my 
application's logic.

     I am doing that, and when the template outputs XML, the content 
type is 'text/xml', but the stylesheet is still not being applied.

Any other ideas?

Garey Mills

Nathan Bubna wrote:
> That all sounds correct.  The only thing i can think of to check on is
> whether any content has been committed to the response or if
> response.getWriter() is called before the setContentType() call
> happens.

> Of course, if one of those things is happening, it should not be due
> to the VelocityViewServlet.  The VVS doesn't send any content or call
> response.getWriter() until after the setContentType() method has been
> called.
> Not sure how much more help i'll be beyond this point...
> On 6/8/07, Garey <> wrote:
>> Nathan -
>>     I believe that I have done what you suggested. I created a class
>> MyVelocityViewServlet that extends VelocityViewServlet. It contains only
>> an overridden setContentType(request, response) which pulls an attribute
>> out of the request and sets the content type of the response based on
>> the value of the attribute.
>>     Through debugging statements, I can see that the attribute I set is
>> picked up and the content type is set (to 'text/xml'): nevertheless, the
>> output of the Velocity template is not being formatted by the stylesheet
>> at the browser; and, when I look at the page info (in Firefox) the
>> content type is 'text/html'.
>>     Is there a further step I have to take?
>> Garey
>> PS - Here is my setContentType
>>    protected void setContentType(HttpServletRequest request,
>> HttpServletResponse response) {
>>         String ct = (String)request.getAttribute("contenttype");
>>         if(ct != null) {
>>             System.out.println("contenttype found: " + ct);
>>             response.setContentType(ct);
>>         } else {
>>             System.out.println("no contenttype attribute found");
>>             super.setContentType(request, response);
>>         }
>>   }
>> Nathan Bubna wrote:
>> > actually, b) is true too.  the VVS does explicitly set the content 
>> type.
>> >
>> > either way, you should extend the VVS.  the key method to override is
>> > the setContentType(request, response) method.
>> >
>> > to be able to tell what content type to set, you will want to push an
>> > indicator (or the content type value itself) into the request
>> > attributes, pull it out in your setContentType() impl and then call
>> > response.setContentType() there.
>> >
>>     On 6/8/07, Garey <> wrote:
>>     Nathan -
>>         I tried setting the content type from the template and no joy. I
>>     also tried setting the content type in the response
>>     from my logic before passing the request off to the
>>     VelocityViewServlet.
>>     Also no go. I suppose that is because either a) the handoff to the
>>     ViewServlet is a forward so the View servlet doesn't even see my
>>     partial
>>     response, or b) the ViewServlet explicitly sets the content type. 
>> Since
>>     a) is more probable, I will probably have to extend the ViewServlet.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message