You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Gioele Barabucci <ba...@cs.unibo.it> on 2005/02/14 00:54:53 UTC

Setting ContentType and encoding for all jsp pages

I want to send the output of my JSPs as "application/xhtml+xml" in UTF-8.

All the pages I send are XHTML in UTF-8, but the browsers can't understand
them because Tomcat (Apache-Coyote/1.1, the one bundled with JBoss 3.2.5)
set Content-Type to text/html without any encoding information.

I tried to put 
  <mime-mapping>
    <extension>jsp</extension>
    <mime-type>application/xhtml+xml</mime-type>
  </mime-mapping>
in web.xml, but this directive seems to be ignored... (how can I test this?)
Also I can't find how to tell Tomcat that the JSP output should be declared
as UTF-8 encoded.

[I know that I can add
  <%@ page contentType="application/xhtml+xml" %>
  <%@ page pageEncoding="UTF-8" %>
to all my pages, but I'd like to avoid this...]

--
Gioele


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


Re: Setting ContentType and encoding for all jsp pages

Posted by Gioele Barabucci <ba...@cs.unibo.it>.
Ethan Sutin wrote:
> http://java.sun.com/products/servlet/Filters.html
I tried also with this filter

/**
 * @web.filter name="ContentType"
 * @web.filter-mapping url-pattern="*.jsp"
 */
public class ContentTypeFilter implements Filter {
  public void doFilter(ServletRequest request,
                       ServletResponse response,
                       FilterChain chain)
    throws IOException, ServletException
  {
    //response.setContentType("application/xhtml+xml;charset=UTF-8");
    response.setContentType("application/xhtml+xml");
    chain.doFilter(request, response);
  }
}

It gets called properly (as some println showed) but the ContentType is
still "text/html".
If I use setContentType("application...;charset=UTF-8"), the "charset=..."
part is preserved in the ContentType that I get, but "application..." is
replaced by "text/html".
Do someone know what is rewriting the HTTP Header?

--
Gioele


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


Re: Setting ContentType and encoding for all jsp pages

Posted by Ethan Sutin <su...@virginia.edu>.
http://java.sun.com/products/servlet/Filters.html

Gioele Barabucci wrote:

>I want to send the output of my JSPs as "application/xhtml+xml" in UTF-8.
>
>All the pages I send are XHTML in UTF-8, but the browsers can't understand
>them because Tomcat (Apache-Coyote/1.1, the one bundled with JBoss 3.2.5)
>set Content-Type to text/html without any encoding information.
>
>I tried to put 
>  <mime-mapping>
>    <extension>jsp</extension>
>    <mime-type>application/xhtml+xml</mime-type>
>  </mime-mapping>
>in web.xml, but this directive seems to be ignored... (how can I test this?)
>Also I can't find how to tell Tomcat that the JSP output should be declared
>as UTF-8 encoded.
>
>[I know that I can add
>  <%@ page contentType="application/xhtml+xml" %>
>  <%@ page pageEncoding="UTF-8" %>
>to all my pages, but I'd like to avoid this...]
>
>--
>Gioele
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>  
>


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