本草汉方增高:struts 的中文乱码问题解决方案(3个)
来源:百度文库 编辑:偶看新闻 时间:2024/04/27 15:40:04
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
//从浏览器中的到的二进制数据用utf-8编码
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
在web.xml文件中配置filter:
②. 提供自定义的 ActionServlet
public class MyActionServlet extends ActionServlet {
private static final long serialVersionUID = 5165092497954010055L;
@Override
protected void process(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
super.process(request, response);
}
}
web.xml 文件中
改为
③. 提供自定义的 RequestProcessor
public class MyRequestProcessor extends RequestProcessor {
@Override
public void process(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
super.process(request, response);
}
}
在 struts-config.xml 文件中加入如下内容:
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}