action调用其他模型的业务层,报空指针问题请教
SSH环境
在打开添加员工页面的时候需要先加载一个部门选择列表,我的想法是点击添加员工按钮时,调用员工action里的一个input方法跳转到添加页面,在input方法里,先使用部门模块的service层查询部门表,将部门表封装进一个list返回到页面。因此在员工action注入了部门的ebi,也就是这个ebi报的空指针异常。
部门模块的增删改查都已经完成了,配置文件也没有问题,员工模块的配置也完成了,登录功能什么的没有问题。哪位高手帮忙看看是哪里出的问题导致没有注入成功呢?
我的代码如下:
EmpAction
applicationContext-dept.xml
applicationContext-emp.xml
applicationContext.xml
web.xml
在打开添加员工页面的时候需要先加载一个部门选择列表,我的想法是点击添加员工按钮时,调用员工action里的一个input方法跳转到添加页面,在input方法里,先使用部门模块的service层查询部门表,将部门表封装进一个list返回到页面。因此在员工action注入了部门的ebi,也就是这个ebi报的空指针异常。
部门模块的增删改查都已经完成了,配置文件也没有问题,员工模块的配置也完成了,登录功能什么的没有问题。哪位高手帮忙看看是哪里出的问题导致没有注入成功呢?
我的代码如下:
EmpAction
//注入业务层接口
private EmpEbi empEbi;
public void setEmpEbi(EmpEbi empEbi) {
this.empEbi = empEbi;
}
private DeptEbi deptEbi;
public void setDeptEbi(DeptEbi deptEbi) {
this.deptEbi = deptEbi;
}
public String input(){
// 从数据库读取部门列表,加载部门选项
List<DeptModel> deptList = deptEbi.getAll(); // 这行的deptEbi报空指针
ActionContext.getContext().put("deptList", deptList);
return "input";
}
applicationContext-dept.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd ">
<!-- 配置Action -->
<bean id = "deptAction" class="cn.lim.erp.auth.dept.web.DeptAction" scope="prototype">
<!-- 注入sessionFactory -->
<property name="deptEbi" ref="deptEbi"></property>
</bean>
<!-- 配置Ebi -->
<bean id = "deptEbi" class="cn.lim.erp.auth.dept.business.ebo.DeptEbo">
<!-- 注入sessionFactory -->
<property name="deptDao" ref="deptDao"></property>
</bean>
<!-- 配置Dao -->
<bean id = "deptDao" class="cn.lim.erp.auth.dept.dao.impl.DeptImpl">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
applicationContext-emp.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd ">
<!-- 配置Action -->
<bean id = "empAction" class="cn.lim.erp.auth.emp.web.EmpAction" scope="prototype">
<!-- 注入sessionFactory -->
<property name="empEbi" ref="empEbi"></property>
</bean>
<!-- 配置Ebi -->
<bean id = "empEbi" class="cn.lim.erp.auth.emp.business.ebo.EmpEbo">
<!-- 注入sessionFactory -->
<property name="empDao" ref="empDao"></property>
</bean>
<!-- 配置Dao -->
<bean id = "empDao" class="cn.lim.erp.auth.emp.dao.impl.EmpImpl">
<!-- 注入sessionFactory -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd" >
<!-- SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
</props>
</property>
<property name="mappingLocations">
<value>classpath:cn/lim/erp/**/vo/*Model.hbm.xml</value>
</property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<!-- 给事务注入hibernate的连接池 -->
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 注解事务驱动 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- DataSource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/erpdb"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts2加载 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring监听器 -->
<listener>
<!-- 监听器默认加载的是WEB-INF/applicationContext.xml -->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 指定Spring框架的配置文件所在的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
</web-app>
...全文
相关推荐
J2EE编程(action之空指针处理)
(名片管理系统)课程设计中关于action的空指针处理问题
通过button将form表单的数据提交到action层的实例
form表单中不需要写action的路径,需要给form表单一个唯一的id,将你要提交的信息的表单中的标签name=”action中的javabean对象.javabean属性”。给button按钮添加一个onclick()点击事件,并实现该点击事件,在该onclick()方法中通过ajax将form表单中的数据提交给action层 JSP页面中的代码: <form id="handleform"> <!-- 根据学生id修改学生信息 --> <input type="hidden" name="student.stuid"/><!-- 隐藏学生id --> <
J2EE编程(action之空指针)
(名片管理系统)课程设计中关于action空指针的问题
jsp自动调用action
jsp自动调用action采用中间jsp方法 就是采用从欢迎页跳到action处理再转到展示页面,就可以访问页面时加载数据
Struts1.2Action之处理多个业务
在J2EE中Structs Action之处理多个业务


Web 开发
