tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric B." <>
Subject Re: How to set ContentType from within Filter?
Date Tue, 22 Jan 2008 03:44:59 GMT
"Christopher Schultz" <> wrote in message
> Hash: SHA1
> Eric,
> Eric B. wrote:
> | Ahhh yes - my mistake for not being clear enough.  I had already
> discovered
> | that.  Or another option is to put <% response.setContentType(
> "text/css" )
> | %>.  However, I am looking more in the sense that I don't want Jasper
> to put
> | anything in my output class.
> I'm not sure if that's going to happen. You could try setting it to an
> empty string, but you're likely to get a blank-string Content-Type
> header, then. I think the JSP compiler really wants to set a content-type.
> | Basically, the issue I am running into right now is that I have CSS 
> pages
> | that have some JSP code in them.
> | Consequently, they need to be compiled.
> :(
> Why are you doing this?

Multiple reasons, one main one primary one being that we have styles defined 
on a per-user basis, stored in a database.  So rather than generate an 
entire CSS file on the fly, this allows us to display certain customizations 
to the styles without any major hassles.

> | However, I don't want to start putting in a tag within each JSP file to
> | indicate that it is a CSS page; rather I'd prefer to use a filter to
> | determine that for me, and set the content type in the filter itself.
> You /could/ wrap the incoming request you pass to chain.doFilter in an
> HttpServletRequestFilter that ignores calls to setContentType (or
> equivalent setHeader("Content-Type", ...) calls).
> That way, your filter has the last word in the Content-Type argument.

Hmmm - interesting thought.  I was thinking something along those lines, but 
for some reason hadn't thought of that exact soln.  If I get a chance in the 
next couple of days I'll try something out and see if it works.  My 
immediate thought, however, would be to subclass the HttpServletResponse 
class and ignore the setContentType() and equv setHeader( "Content-Type"...) 
methods if they have already been set by my filter or something like that. 
I'm not sure what you mean by HttpServletRequestFilter, or if you mean 
exactly the same thing that I just described.

Thanks again,


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message