我的BBS开发问题解决笔记
1.在提交用户注册时,程序后台报错如下: [color=red]java.lang.NullPointerException at com.zhk.mybbs.struts.action.UserAction.register(UserAction.java:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) ..........[/color] **原因据说是:action中的iuserdao没有实例化。 ***解决方案:在applicationContext.xml中添加以下代码: [code="java"] [/code] 2.注册页面的图形验证码页面(image.jsp)报错: [color=red]严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response ........ [/color] **原因:response.getWriter()方法和response.getOutputStream()方法相冲突。 ***解决:在使用完输出流以后(即jsp页面最后)添加以下代码即可: [code="java"] out.clear(); out = pageContext.pushBody(); [/code] 3.hibernate连接数据库出错: [color=red]org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) ............ [/color] ***解决:将 .xml 中连接数据库的代码[code="错误"] [/code] 换成: [code="正确"] org.gjt.mm.mysql.Driver jdbc:mysql://localhost:3306/mybbs root mmmmmm [/code] 4.user对象中的字段类型错误: [color=red]org.hibernate.PropertyAccessException: IllegalArgumentException[/color] ***解决:将User.java对象中的字段类型和数据库中的字段类型调成一致即可.如:数据库中的grade 字段为 int 型,那么User对象中就应该是 private int grade;