我用SSH 框架写了个项目 吧action交给spring 那种的 但现在向action提交数据的时候会出现乱码 我写了dofilter也没用
急
web.xml
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>com.gh.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>SetCharacterEncodingFilter class public class SetCharacterEncodingFilter implements Filter { private String encoding;
private FilterConfig filterConfig = null;
public void destroy() {
this.encoding = "utf-8";
this.filterConfig = null; } public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(this.encoding);
chain.doFilter(request, response);
System.out.println("doFilter-------"+ this.encoding);
} public void init(FilterConfig filterConfig) throws ServletException {
this.encoding = filterConfig.getInitParameter("encoding");
}
}
急
web.xml
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>com.gh.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>SetCharacterEncodingFilter class public class SetCharacterEncodingFilter implements Filter { private String encoding;
private FilterConfig filterConfig = null;
public void destroy() {
this.encoding = "utf-8";
this.filterConfig = null; } public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(this.encoding);
chain.doFilter(request, response);
System.out.println("doFilter-------"+ this.encoding);
} public void init(FilterConfig filterConfig) throws ServletException {
this.encoding = filterConfig.getInitParameter("encoding");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货