KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > charset > CharsetResponse


1 package com.tonbeller.wcf.charset;
2
3 import java.util.Locale JavaDoc;
4
5 import javax.servlet.ServletResponse JavaDoc;
6 import javax.servlet.http.HttpServletResponse JavaDoc;
7 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
8
9 /**
10  * a response wrapper that does not allow the character encoding to be changed.
11  * Problem: in servlet 2.3, when {@link ServletResponse#setLocale(java.util.Locale)}
12  * is called, the character encoding is changed implicit in an unspecified way.
13  * To prevent this, this wrapper does not forward the setLocale call.
14  * All JSTL fmt:xxx actions call setLocale on the response, which causes
15  * the problem.
16  * see JSTL spec, section 8.4
17  * @see ServletResponse#setLocale(java.util.Locale)
18  *
19  * @author av
20  * @since 19.05.2005
21  */

22 class CharsetResponse extends HttpServletResponseWrapper JavaDoc {
23   private String JavaDoc contentType;
24   private String JavaDoc encoding;
25   public CharsetResponse(HttpServletResponse JavaDoc resp, String JavaDoc contentType, String JavaDoc encoding) {
26     super(resp);
27     this.contentType = contentType;
28     this.encoding = encoding;
29   }
30   
31   public void setLocale(Locale JavaDoc arg0) {
32     // ignore
33
}
34   
35   public void setContentType(String JavaDoc ct) {
36     if (contentType != null && ct != null && ct.startsWith(contentType))
37       ct = contentType + ";charset=" + encoding;
38     super.setContentType(ct);
39   }
40
41 }
42
Popular Tags