就是在一个JSP页面接收ActionForm的属性时,如果输入的是中文,那么在ActionForm接收后会是乱码
解决方案有2个:
1.在Action类中解决,这个我试过,不可行
2.在ActionForm中解决,这个我试过,可行,而且很方便
在ActionForm中的reset方法中加入如下代码即可,可输出英文或中文
public void reset(ActionMapping mapping, HttpServletRequest request) { try { request.setCharacterEncoding("GBK"); } catch (Exception e) { // TODO: handle exception } }
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { PersonalForm personalForm = (PersonalForm) form;// TODO Auto-generated method stub System.out.println(personalForm.getUsername()); System.out.println(personalForm.getPassword()); return mapping.findForward("step2"); }