1.在提交用户注册时,程序后台报错如下:
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)
..........
**原因据说是:action中的iuserdao没有实例化。
***解决方案:在applicationContext.xml中添加以下代码:
<bean name="/jsp/user"
class="com.zhk.mybbs.struts.action.UserAction">
<property name="iuserdao">
<ref bean="iuserdaoimpl" />
</property>
</bean>
2.注册页面的图形验证码页面(image.jsp)报错:
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
........
**原因:response.getWriter()方法和response.getOutputStream()方法相冲突。
***解决:在使用完输出流以后(即jsp页面最后)添加以下代码即可:
out.clear();
out = pageContext.pushBody();
3.hibernate连接数据库出错:
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
............
***解决:将 .xml 中连接数据库的代码
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/mybbs"></property>
</bean>
换成:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>org.gjt.mm.mysql.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/mybbs</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>mmmmmm</value>
</property>
</bean>
4.user对象中的字段类型错误:
org.hibernate.PropertyAccessException: IllegalArgumentException
***解决:将User.java对象中的字段类型和数据库中的字段类型调成一致即可.如:数据库中的grade 字段为 int 型,那么User对象中就应该是 private int grade;