UTF-8 Filter: public class UTF8Filter implements Filter { public void init(FilterConfig config) throws ServletException { }
public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); chain.doFilter(request, response); } } ISO88591 Filter: public class ISO88591Filter implements Filter { public void init(FilterConfig config) throws ServletException { VenarcLogger.log(3, "Starting filter."); } public void destroy() { VenarcLogger.log(3, "Destroying filter."); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("ISO8859-1"); response.setCharacterEncoding("ISO8859-1"); VenarcLogger.log(VenarcLogger.LEVEL_MIN, "Setting request to " + request.getCharacterEncoding()); chain.doFilter(request, response); } } Then in web.xml <filter> <filter-name>UTF-8</filter-name> <filter-class>com.acme.filter.UTF8Filter</filter-class> </filter> <filter> <filter-name>ISO8859-1</filter-name> <filter-class>com.acme.filter.ISO88591Filter</filter-class> </filter> <filter-mapping> <filter-name>UTF-8</filter-name> <url-pattern>/getProductsInternational*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>ISO88591</filter-name> <url-pattern>/getProductsLocal*</url-pattern> </filter-mapping> hope this helps. cheers, Drew Kutcharian Venarc Inc. www.venarc.com ----- Original Message ---- From: red phoenix <[EMAIL PROTECTED]> To: Struts Users Mailing List <user@struts.apache.org> Sent: Thursday, April 19, 2007 9:44:54 PM Subject: Re: How to set filter in Struts2? Would you give me a simple code for it? On 4/20/07, Drew Kutcharian <[EMAIL PROTECTED]> wrote: > > Can you use different filters/filter mappings for different URL patterns? > > Drew Kutcharian > Venarc Inc. www.venarc.com > > > > ----- Original Message ---- > From: red phoenix <[EMAIL PROTECTED]> > To: Struts Users Mailing List <user@struts.apache.org> > Sent: Thursday, April 19, 2007 7:58:47 PM > Subject: How to set filter in Struts2? > > I want to set a filter,then I set different character code by this > filter,such when a request from a1.action,I will set this character code > is > UTF-8,a request from a2.action,I will set this character code is > ISO88591,and so on.I don't know how to realize above function in filter? > Anybody could tell me how to do it? > > Thanks. > > > > >