关于ssh纠错笔记

  1. 如果定义了一个bean,如User类,在action中就要new它,即User user= new User(),不然的话,拿不到页面传过来的数据.

对于中文乱码问题,可以先设置一个乱码过滤器,在过滤器中设置为

  arg0.setCharacterEncoding("GB18030");

    arg2.doFilter(arg0, arg1);

这样如果还是会出现中文乱码就需要在struts2.xml中设置常属性了,为

<constant name="struts.i18n.encoding" value="GB18030"></constant>

基本就可以解决问题了。

  2.对于request问题,最好是使用ServletRequestAware接口实现,还应在类中定义HttpServletRequest属性,并生成get和set方法,还应实现接口中的一个抽象类setServletRequest(HttpServletRequest arg0),在该方法中应该注意,不要自以为的写this.request= request(错的),应该写为this.request = arg0;不然就会在这request.setAttribute(“hello”,”hello”),这里报错。

  3.当在JSP页面向action提交的内容出现乱码的时候可以使用       <constant name="struts.locale" value="zh_CN"></constant>

   <constant name="struts.i18n.encoding" value="GB18030"></constant>

可以消除乱码。

  4.Duplicate class/entity mapping com.exam.model.ChoiceMode可能是映射表映射错误,可能是你复制其他表,但是class这些没改过来

  5.当你使用ajax与struts进行登陆验证的时候,如果对哪个方法进行了两次操作,可能就是你的表单写了action和method方法,还有就是你的提交按钮写了点击事件,当你点击按钮的时候会触发点击事件,当执行完之后就马上执行form中的方法

  6.No result defined for action com.nky.action.FileOperationAction and result input通常是在struts.xml中的result中配置出现问题,比如文件的上传,你在action中只是写了成功之后跳转的页面但是失败的页面没有配置好,这时你应该在配置文件中多加一个result并且命名为input

  7.<param name="allowedExtensions">xls,xlsx</param>允许后缀名为xlsx,xls的文件上传

  8.   java.lang.NoSuchMethodException: com.csdnsoft.web.action.NewsAction.$list()可能是在action中的方法没有定义为public

  9.java.lang.IllegalArgumentException: node to traverse cannot be null!通常是在hibernate的查询语句中出错了

  10.java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher 
Could not initialize class  net.sf.json.util.JSONUtils 出现这种异常通常是因为缺少了jar包

ezmorph-1.0.6.jar 
commons-lang 2.4 
commons-beanutils 1.7.0 
commons-collections 3.2 
commons-logging 1.1.1

最大可能缺少的是第一个包

  11.Unknown column '...' in 'where clause'可能是你写的sql语句出错,比如select * from user u where u.name=aa;就报错了应该在aa加上单引号

  12.当加载进jsp页面的js代码出现乱码时,可能是因为我们在项目工程中所创建的文件不是以utf-8这种格式的,需要转码,可用编辑器转成utf-8即可

  13.org.hibernate.PropertyNotFoundException: Could not find a getter for XXX这次出现这个问题是因为在数据库中的一个属性设置为getDoc,然后再生成实体类的时候有getgetDoc方法,导致出错

原文地址:https://www.cnblogs.com/luoweiKnowledge/p/3957519.html