CSDN博客

img baoqingfeng

struts 问题集

发表于2004/9/24 20:55:00  840人阅读

  • struts form提交普通控件时,Action中得到的值是乱码,要在web.xml文件中用Filter处理 <filter>
      <filter-name>EncodingFilter</filter-name>
      <filter-class>com.jbbis.scms.filter.EncodingFilter</filter-class>
      <init-param>
       <param-name>Encoding</param-name>
       <param-value>GBK</param-value>
      </init-param>
     </filter>
     <filter-mapping>
      <filter-name>EncodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
     </filter-mapping>public class EncodingFilter implements Filter {
     private String encoding = "GBK";

 

EncodingFilter类:
 /* (non-Javadoc)
  * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
  */
 public void init(FilterConfig fc) throws ServletException {
  String s = fc.getInitParameter("Encoding");
  if (s != null) {
   this.encoding = s;
  }
 }

  •  /* (non-Javadoc)
      * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
      */
     public void doFilter(
      ServletRequest request,
      ServletResponse response,
      FilterChain fc)
      throws IOException, ServletException {
      request.setCharacterEncoding(encoding); 
      fc.doFilter(request, response);
     } /* (non-Javadoc)
      * @see javax.servlet.Filter#destroy()
      */
     public void destroy() {
     }
  • eclipse 中的cvs不能正确commit时请刷新工程
阅读全文
0 0

相关文章推荐

img
取 消
img