Please bear with me for a moment here, I am a bit confused at how the doFilter() works. In servlet javadoc:
The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain. Let's see whether I understand correctly. So the init() method is called when the application deploys. But since congif is null at that time, the targetEncoding is set to null in the init(). As is reflected in this.targetEncoding = config.getInitParameter("encoding"); So when I try to do the Filter, since the request doesn't have any encoding information, the request.setCharacterEncoding(targetEncoding); is going to set the charater encoding to null. And that's exactly what I got: java.lang.NullPointerException: charsetName at java.lang.String.(String.java:329) at java.lang.String.(String.java:359) at org.apache.coyote.tomcat4.CoyoteRequest.setCharacterEncoding(CoyoteRequest.java: 1198) at org.apache.coyote.tomcat4.CoyoteRequestFacade.setCharacterEncoding(CoyoteRequest Facade.java:157) at org.j2ee_test.util.EncodingFilter.doFilter(EncodingFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt erChain.java:213) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. java:193) ... So if I default request.setCharacterEncoding("UTF-8"); Everything works fine. So I guess what I don't understand is when you have the character encoding attribute for a page. It makes sense to me that when processing the request, Filter should already know what kind of targetEncoding it is. But the example code below obviously does not provide that mechanism. Here is what I have in my web.xml, no sure if it helps: <filter> <filter-name>EncodingFilter</filter-name> <display-name>EncodingFilter</display-name> <description></description> <filter-class>org.j2ee_test.util.EncodingFilter</filter-class> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/</url-pattern> </filter-mapping> Again thanks for the help. -----Original Message----- From: Vernon Smith [mailto:[EMAIL PROTECTED] Sent: Thursday, December 04, 2003 1:35 PM To: Tag Libraries Users List Subject: Re: Request encoding problem You also need to set up the input field encoding in addition of page character set. You can do so field by field to convert the input string encoding or using the following filter from the PetStore. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mport java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; public class EncodingFilter implements Filter { // default to ASCII private String targetEncoding = "ASCII"; public void init(FilterConfig config) throws ServletException { this.targetEncoding = config.getInitParameter("encoding"); } public void destroy() { targetEncoding = null; } public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)srequest; request.setCharacterEncoding(targetEncoding); // move on to the next chain.doFilter(srequest,sresponse); } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And setup this filter for all JSP files in your web.xml. Hope this helps. -- --------- Original Message --------- DATE: Thu, 4 Dec 2003 12:58:54 From: "Yansheng Lin" <[EMAIL PROTECTED]> To: "'Tag Libraries Users List'" <[EMAIL PROTECTED]> Cc: > >Hi, > >I have trouble processing user's input using UTF-8 encoding. I can change to >different locales with > <fmt:setLocale value='${sessionScope["org.apache.struts.action.LOCALE"]}'/>, >but I don't think > <fmt:requestEncoding value='UTF-8'/> >is working for me right now. I already set the page encoding in my hearder with: > <meta http-equiv="content-type" content="text/html; charset=UTF-8"> > >Here is my Systen.out in the beginning of dispatchAction(): > > System.out.println(request.getCharacterEncoding()); > System.out.println(request.getContentType()); > System.out.println(request.getLocale()); > >And this is what I get: > null > application/x-www-form-urlencoded > en_US > >I am not sure what's missing right now. Do I have to set anything in the >web.xml? > >Thanks in advance! > >-Yan > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > ____________________________________________________________ Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail! http://login.mail.lycos.com/r/referral?aid=27005 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]