tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hassan Schroeder <has...@webtuitive.com>
Subject Re: valid XHTML 1.1, Tomcat, text/xml, and @!&* IE
Date Sat, 18 Sep 2004 17:54:48 GMT
Garret Wilson wrote:

> Oh, this is just a nightmare.
> 
> Using JavaServer Faces, here are the options:
> 
> 1. Just add a JSP directive:
> 2. Add a script to check for what the browser accepts:

3. Use a Filter -- here's a quick example, you may need to tweak it
    for your particular situation --

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public class Accept implements Filter {

   private FilterConfig config = null;
   private String  htmlContentType = "text/html";
   private String xhtmlContentType = "application/xhtml+xml";

   public void init(FilterConfig config) throws ServletException
   {
     this.config = config;
   }

   public void destroy()
   {
     config = null;
   }

   public void doFilter(ServletRequest request, ServletResponse response,
                  FilterChain chain) throws IOException, ServletException
   {
     String thisContentType = "";
     if (request instanceof HttpServletRequest)
     {
       String AcceptHeader = 
((HttpServletRequest)request).getHeader("Accept").toString();

       if ( AcceptHeader.matches(".*application/xhtml\\+xml.*") )
       {
         thisContentType = xhtmlContentType;
       }
       else
       {
         thisContentType = htmlContentType;
       }
     }
     response.setContentType(thisContentType);
     chain.doFilter(request, response);
   }
}

HTH!
-- 
Hassan Schroeder ----------------------------- hassan@webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.



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


Mime
View raw message