日期:2014-05-19  浏览次数:20812 次

spring +struts2 中set注入问题求高手指点怎么老是出错...
这个是接口 UserInterFace 的方法:
public boolean loGin(String userName,String userPwd);
这个是接口的实现类UserFunction 方法:
/**用户登录方法**/
public boolean loGin(String userName,String userPwd){
boolean scu=false;
try
{
ConnDB conn=new ConnDB();
String sql="select userpwd from userTB where username='"+userName+"'";
ResultSet rs= conn.executeQuery(sql);
if(rs.next()){
String password =rs.getString(1);
if(userPwd.equals(password)){
scu=true;
}
}
conn.close();
}
catch(Exception e){e.printStackTrace();}
return scu;
}
这个是spring配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="ConnDB" class="org.com.wzy.clzy.db.ConnDB"></bean>

<bean id="UserFunction" class="org.com.wzy.clzy.function.user.UserFunction"></bean>

<bean id="LoginAction" class="org.com.wzy.clzy.actions.login.LoginAction">
<property name="uf" ref="UserFunction"/>
</bean>

</beans>

提示的错误就是:
java.lang.NullPointerException
org.com.wzy.clzy.actions.login.LoginAction.yzlogin(LoginAction.java:38)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)

------最佳解决方案--------------------
把你的struts的配置文件贴出来,和你的loginAction的属性
------其他解决方案--------------------

org.com.wzy.clzy.actions.login.LoginAction.yzlogin(LoginAction.java:38)

查找错误信息,再仔细找找
------其他解决方案--------------------
空了。