日期:2014-05-16  浏览次数:20614 次

数据库插入对象时报java.lang.NullPointerException异常
点击下面标题查看本文完整版:数据库插入对象时报java.lang.NullPointerException异常Java code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->package com.yu.znt.dao;public interface IUserDAO { public void register(User user) throws Exception;}



?

Java code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->package com.yu.znt.dao.impl;public class IUserDAOImpl extends HibernateDaoSupport implements IUserDAO { public void register(User user) throws Exception{  super.getSession().save(user); }}



在userAction中已经set/get方法
?

Java code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public class UserAction extends DispatchAction {  private IUserDAO iuserdao;  ...  public ActionForward register(ActionMapping mapping, ActionForm form,  HttpServletRequest request, HttpServletResponse response) {  ...  this.iuserdao.register(user);  ...}...



其它代码,我只帖重要地方
web.xml

?

Java code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->... <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet>  <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>... 



applicationContext.xml

?

Java code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  <property name="dataSource">  <ref bean="dataSource" />  </property>  <property name="hibernateProperties">  <props>   <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect   </prop>   <!-- 表示允许自动提交 -->   <prop key="hibernate.connection.autocommit">true</prop>   <!-- 表示显示sql语句 -->   <prop key="hibernate.show_sql">false</prop>  </props>  </property>  <property name="mappingResources">  <list>   <value>com/yu/znt/model/User.hbm.xml</value>  </list>  </property> </bean>  <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">  <property name="sessionFactory">  <ref bean="sessionFactory"/>  </property> </bean>  <bean id="iuserdao" class="com.yu.znt.dao.IUserDAO" abstract="true"></bean> <bean id="iuserdaoimpl" class="com.yu.znt.dao.impl.IUserDAOImpl" parent="iuserdao">  <property name="hibernateTemplate">  <ref bean="hibernateTemplate"/>  </property> </bean>



struts-config.xml
?

Java code
<!--Code highlighting produced