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

数据库插入对象时报java.lang.NullPointerException错误

2012-12-24 
数据库插入对象时报java.lang.NullPointerException异常点击下面标题查看本文完整版:数据库插入对象时报ja

数据库插入对象时报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"  />  </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" abstract="true"></bean> <bean id="iuserdaoimpl" parent="iuserdao">  <property name="hibernateTemplate">  <ref bean="hibernateTemplate"/>  </property> </bean>



struts-config.xml
?

Java code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><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 processor/> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">   <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />  </plug-in>     

热点排行