数据库插入对象时报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;}
?
<!--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方法
?
<!--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
?
<!--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
?
<!--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
?
<!--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>