最近学习SSH,遇到一个诡异问题,实在被整得没有脾气了,上来求求各位达人帮忙解决。
问题描述:
系统从页面传过来的值在后台获取到了,但是经过spring注入传值的时候就出了问题,传不了值,都成为了null。
以下是主要的代码
applicationContext.xml中:
<bean id="loginService" class="service.LoginServiceImpl" scope="prototype">
<property name="usersDao">
<ref bean="usersDao"/>
</property>
</bean>
<bean id="login" class="action.Common" scope="prototype">
<property name="loginService">
<ref bean="loginService"/>
</property>
</bean>
Common.java中部分代码:
private LoginService loginService;
Users users;
public String login(){
users = loginService.findUser(userId, pwd);
if(null==users)
return "error";
else
return "success";
//return returnStr;
}
此处能够取到页面传过来的值,省略了loginService的getter和setter方法。LoginServiceImpl.java中的部分代码:
public Users findUser(String userId, String pwd) {
// TODO Auto-generated method stub
Users users = usersDao.findById(userId, pwd);
return users;
}
打了断点调试,程序能够执行到这里。问题就是这里取不到Common.java中传过来的值。求大虾们帮帮忙解决下,急着用。谢了。
问题描述:
系统从页面传过来的值在后台获取到了,但是经过spring注入传值的时候就出了问题,传不了值,都成为了null。
以下是主要的代码
applicationContext.xml中:
<bean id="loginService" class="service.LoginServiceImpl" scope="prototype">
<property name="usersDao">
<ref bean="usersDao"/>
</property>
</bean>
<bean id="login" class="action.Common" scope="prototype">
<property name="loginService">
<ref bean="loginService"/>
</property>
</bean>
Common.java中部分代码:
private LoginService loginService;
Users users;
public String login(){
users = loginService.findUser(userId, pwd);
if(null==users)
return "error";
else
return "success";
//return returnStr;
}
此处能够取到页面传过来的值,省略了loginService的getter和setter方法。LoginServiceImpl.java中的部分代码:
public Users findUser(String userId, String pwd) {
// TODO Auto-generated method stub
Users users = usersDao.findById(userId, pwd);
return users;
}
打了断点调试,程序能够执行到这里。问题就是这里取不到Common.java中传过来的值。求大虾们帮帮忙解决下,急着用。谢了。
<property name="loginService">
<ref bean="loginService"/>
</property>
</bean>
这个<bena id="login">
应该改为<bean name="login">
users = loginService.findUser(userId, pwd);
}
userId, pwd这两个参量你在哪里定义的???
Common.java中部分代码:
private LoginService loginService;
Users users;
public String login(){
users = loginService.findUser(userId, pwd);
if(null==users)
return "error";
else
return "success";
//return returnStr
MARK。。
眼睛有些疼,没好好看你的代码。。
明儿再看。。