请问我这里是什么地方错了 报 500 空指针错误 请帮我看一下 谢谢!
请求链接:
<li><a href="type_findAllType.action" target="mainFrame">类型显示</a></li>struts.xml:<action name="type_*" class="com.action.TypeAction" method="{1}">
<result name="lgnOk">ok.jsp</result>
<result name="showTypeOk">tyepShow.jsp</result>
</action>Action:package com.action;import java.util.List;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.Pftype;public class TypeAction extends ActionSupport{
//表单
private com.pojo.Pftype type;
//action依赖对象
private com.biz.TypeBizInf typebiz; private List<Pftype> types;
public List<Pftype> getTypes() {
return types;
} public void setTypes(List<Pftype> types) {
this.types = types;
} public com.pojo.Pftype getType() {
return type;
} public void setType(com.pojo.Pftype type) {
this.type = type;
} public com.biz.TypeBizInf getTypebiz() {
return typebiz;
} public void setTypebiz(com.biz.TypeBizInf typebiz) {
this.typebiz = typebiz;
}
//-----------------------------------------------------------------------
public String findAllType(){
types = typebiz.findType(); //debug模式 到这里停了 提示 空指针
return "showTypeOk";
}
}service层:Interface:package com.biz;import java.util.List;import com.pojo.Pftype;
public interface TypeBizInf { List<Pftype> findType();
}
Imp:package com.biz;import java.util.List;import com.pojo.Pftype;public class TypeBizImp implements TypeBizInf {
private com.dao.PftypeDAO typedao;
//get set
public com.dao.PftypeDAO getTypedao() {
return typedao;
} public void setTypedao(com.dao.PftypeDAO typedao) {
this.typedao = typedao;
}
public List<Pftype> findType() {
// TODO Auto-generated method stub
return typedao.findAll();
}
}
DAO层:package com.dao;import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.pojo.Pftype;
public class PftypeDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(PftypeDAO.class);
// property constants
public static final String NMBER = "nmber";
public static final String TNAME = "tname";
public static final String TYPE_ID = "typeId";
public static final String TIP_ID = "tipId";
public static final String INFO = "info"; protected void initDao() {
// do nothing
} public List findAll() {
log.debug("finding all Pftype instances");
try {
String queryString = "from Pftype";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public static PftypeDAO getFromApplicationContext(ApplicationContext ctx) {
return (PftypeDAO) ctx.getBean("PftypeDAO");
}
}
请求链接:
<li><a href="type_findAllType.action" target="mainFrame">类型显示</a></li>struts.xml:<action name="type_*" class="com.action.TypeAction" method="{1}">
<result name="lgnOk">ok.jsp</result>
<result name="showTypeOk">tyepShow.jsp</result>
</action>Action:package com.action;import java.util.List;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.Pftype;public class TypeAction extends ActionSupport{
//表单
private com.pojo.Pftype type;
//action依赖对象
private com.biz.TypeBizInf typebiz; private List<Pftype> types;
public List<Pftype> getTypes() {
return types;
} public void setTypes(List<Pftype> types) {
this.types = types;
} public com.pojo.Pftype getType() {
return type;
} public void setType(com.pojo.Pftype type) {
this.type = type;
} public com.biz.TypeBizInf getTypebiz() {
return typebiz;
} public void setTypebiz(com.biz.TypeBizInf typebiz) {
this.typebiz = typebiz;
}
//-----------------------------------------------------------------------
public String findAllType(){
types = typebiz.findType(); //debug模式 到这里停了 提示 空指针
return "showTypeOk";
}
}service层:Interface:package com.biz;import java.util.List;import com.pojo.Pftype;
public interface TypeBizInf { List<Pftype> findType();
}
Imp:package com.biz;import java.util.List;import com.pojo.Pftype;public class TypeBizImp implements TypeBizInf {
private com.dao.PftypeDAO typedao;
//get set
public com.dao.PftypeDAO getTypedao() {
return typedao;
} public void setTypedao(com.dao.PftypeDAO typedao) {
this.typedao = typedao;
}
public List<Pftype> findType() {
// TODO Auto-generated method stub
return typedao.findAll();
}
}
DAO层:package com.dao;import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.pojo.Pftype;
public class PftypeDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(PftypeDAO.class);
// property constants
public static final String NMBER = "nmber";
public static final String TNAME = "tname";
public static final String TYPE_ID = "typeId";
public static final String TIP_ID = "tipId";
public static final String INFO = "info"; protected void initDao() {
// do nothing
} public List findAll() {
log.debug("finding all Pftype instances");
try {
String queryString = "from Pftype";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public static PftypeDAO getFromApplicationContext(ApplicationContext ctx) {
return (PftypeDAO) ctx.getBean("PftypeDAO");
}
}
解决方案 »
- Linux下 org.w3c.dom包解析XML出错
- 请问:在url中传递多个参数该是怎么写法
- 大虾救命啊!!!动态生成的struts标签没有解释
- 那位能给小弟解释解释这几个东东 刚接触B/S!!
- 加急:我有一项目5000左右外包(生手勿试) ,C#+SQL2000,我的QQ48225252
- javaSrcipt
- 可以用Servlet动态生成一个jdbc.odbc数据源吗?
- 下面一些术语哪些是可以说的?
- 换页中出现小问题?大家来看看。。
- 跪求spring.framework-3.0.5.RELEASE-dependencies.zip下载地址
- 用DButils between语句该怎么写?
- 初级人员的迷茫,请解惑
@Resource(name = "sjzdServiceImpl")
private SjzdService sjzdService;
推荐用注解
<!-- type -->
<bean id="TypeBizImp" class="com.biz.TypeBizImp">
<property name="typedao" ref="PftypeDAO"></property>
</bean><!-- type -->
<bean id="TypeAction" class="com.action.TypeAction">
<property name="typebiz" ref="TypeBizImp"></property>
</bean>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/platform?useunicode=true&characterEncoding=utf8">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<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>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/pojo/Pfgameinfo.hbm.xml</value>
<value>com/pojo/Pfpwques.hbm.xml</value>
<value>com/pojo/Pfpicture.hbm.xml</value>
<value>com/pojo/Pftype.hbm.xml</value>
<value>com/pojo/Pfadmin.hbm.xml</value>
<value>com/pojo/Pfserver.hbm.xml</value>
<value>com/pojo/Pfsmallgameinfo.hbm.xml</value>
<value>com/pojo/Pfnews.hbm.xml</value>
<value>com/pojo/Pftopup.hbm.xml</value>
<value>com/pojo/Pflogin.hbm.xml</value>
<value>com/pojo/Pfrole.hbm.xml</value>
<value>com/pojo/Pfuser.hbm.xml</value></list>
</property></bean>
<bean id="PfgameinfoDAO" class="com.dao.PfgameinfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfpwquesDAO" class="com.dao.PfpwquesDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfpictureDAO" class="com.dao.PfpictureDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PftypeDAO" class="com.dao.PftypeDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfadminDAO" class="com.dao.PfadminDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfserverDAO" class="com.dao.PfserverDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfsmallgameinfoDAO" class="com.dao.PfsmallgameinfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfnewsDAO" class="com.dao.PfnewsDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PftopupDAO" class="com.dao.PftopupDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfloginDAO" class="com.dao.PfloginDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfroleDAO" class="com.dao.PfroleDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PfuserDAO" class="com.dao.PfuserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- spring声明式事务管理器 -->
<bean id="hibTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 声明式事务的通知 -->
<tx:advice id="txAdvice"
transaction-manager="hibTransactionManager">
<!-- 指定传播行为 -->
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="bizMethods"
expression="execution(* com.biz.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
</aop:config>
<!-- biz -->
<!-- admin -->
<bean id="AdminBizImp" class="com.biz.AdminBizImp">
<property name="admindao" ref="PfadminDAO"></property>
</bean>
<!-- type -->
<bean id="TypeBizImp" class="com.biz.TypeBizImp">
<property name="typedao" ref="PftypeDAO"></property>
</bean>
<!-- actions -->
<!-- admin -->
<bean id="AdminAction" class="com.action.AdminAction" scope="prototype">
<property name="adminbiz" ref="AdminBizImp"/>
</bean>
<!-- type -->
<bean id="TypeAction" class="com.action.TypeAction">
<property name="typebiz" ref="TypeBizImp"></property>
</bean>
</beans>
if(typebiz!=null)
{
types = typebiz.findType();
}