在使用Struts中的动态ActionForm 在jsp页面中读取的数据乱码 小弟现在学习Struts框架 本来今天做个使用动态ActionForm的实例 但是我页面提交的数据 在ActionFormat收集时出现乱码 我知道在ActionFrom中可以 使用reset方法设置一下编码 但是动态的怎么实现呢? 页面的编码格式我统一为的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以试着用过滤器 或者重写struts中的一个类 public class Filter extends HttpServlet implements javax.servlet.Filter { public void destroy() { super.destroy(); } public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { arg0.setCharacterEncoding("gbk"); arg1.setCharacterEncoding("gbk"); arg2.doFilter(arg0, arg1); } public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub } } 你用这个试试~~ 可以用过滤器,或写一个类继承ActionServlet,并实现ActionServlet类里的一个方法,在这个类中处理乱码,然后所有的请求经过这个类,在web.xml配置,把提交到ActionServlet的请求改成这个类,和过滤器类似!public class Action extends ActionServlet { protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("GBK"); //处理乱码! super.process(request, response); }} <controller processorClass="com.accp.common.MyRequestProcessor" />struts-config.xml里的配置 MyRequestProcessor这个类修改为:public class MyRequestProcessor extends RequestProcessor { public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); super.process(request, response); }} 如何增加在删除记录时弹出对话框提示是否确认删除此信息的代码 yguard混淆问题 页面上如何把数字和字母的组合转换成条码? 求一个从数据库中提取的下拉列表 HIBERNATE未提交,数据自动保存到数据库,奇怪! 救命啊 老板明天就回来了 我又回来问问题了...统计网页内有多少张相同的图 请问怎么在jsp中执行windows的批处理文件? 小弟做了一JSP应放在哪个目录下? JSP传递参数 为什么session总是取不到值? 同一用户登录问题
super.destroy();
}
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
arg0.setCharacterEncoding("gbk");
arg1.setCharacterEncoding("gbk");
arg2.doFilter(arg0, arg1);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
} 你用这个试试~~
HttpServletResponse response) throws IOException, ServletException {
request.setCharacterEncoding("GBK"); //处理乱码!
super.process(request, response);
}}
MyRequestProcessor这个类修改为:
public class MyRequestProcessor extends RequestProcessor { public void process(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
super.process(request, response);
}}