首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

数据库插入对象时报java.lang.NullPointerException异常

2014-01-26 
Java codepackage com.yu.znt.daopublic interface IUserDAO { public void register(User user) throws E

Java code
package com.yu.znt.dao;public interface IUserDAO { public void register(User user) throws Exception;}



 

Java code
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
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
... <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
<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
<form-beans > <form-bean name="userForm" type="com.yu.znt.struts.form.UserForm" /> </form-beans> <global-exceptions /> <global-forwards />  <action-mappings > <action input="/jsp/errors.jsp" name="userForm" parameter="status" path="/jsp/user" scope="request" type="com.yu.znt.struts.action.UserAction">  <forward name="registersuccess" path="jsp/index.jsp"></forward>  <forward name="registerfail" path="/jsp/register.jsp"></forward>  </action> </action-mappings>  <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>  <message-resources parameter="com.yu.znt.struts.ApplicationResources" /> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">   <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />  </plug-in>         

热点排行