开发者

Force Specific Response Header for JSF webapplication on Glassfish

We have a Java EE 6 web application with JSF 2.0 running on Glassfish 3.1.

There we encountered a strange bug: the Mime type of the response header send by Glassfish to the client depends on the order of the allowed Mime types in the request header send by the Browser. So in some cases (depending on the browser), the Mime type of the response is wrong, resulting in a broken html page. But it would take pretty long to explain that thing. So to workaround this problem we now want to do just one thing:

Force the response header type for the whole web-application to "text/html".

Currently, we do that with a Servlet Filter configured in the Web.xml:

@WebFilter("/BaseFilter")
public class BaseFilter implements Filter {
     public BaseFilter() {
     }

     public void destroy() {
     }

     public void doFilter(ServletRequest request, ServletResponse response, 
                          FilterChain chain) throws IOException, ServletException {
         response.setContentType("text/html;charset=UTF-8");
         chain.doFilter(request, response);
     }

     public void init(FilterConfig fConfig) throws ServletException {
     }
 }

configuration in web.xml:

<filter>
  <filter-name>BaseFilter</filter-name>
  <filter-class>com.company.web.filter.BaseFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>BaseFilter</filter-name>
  <url-pattern>/*</url-pattern> 
  <!-- these patterns should match cached resources -->
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
</filter-mapping>
开发者_如何转开发

So my question is, is there a better way to enforce a specific response header, especially by just configuring it instead of implementing a ServletFilter?

Is there a Glassfish option to do that?


You can specify it in the default template by the contentType attribute of the <f:view>.

<f:view contentType="text/html">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜