sturts
public class LoginAction extends Action {
//利用spring來注入這個對象
private LoginDao dao ;
public void setDao(LoginDao dao) {
System
this
}
public LoginDao getDao() {
return dao;
}
public ActionForward execute(ActionMapping mapping
HttpServletRequest request
LoginForm loginForm = (LoginForm) form;// TODO Auto
//這樣一改這行代碼似乎沒有必要了
//WebApplicationContext ctx = this
//LoginDao dao = (LoginDao) ctx
User u = new User();
u
u
//直接用dao來調用spring會將這個對象實例化
if(dao
return mapping
}else{
return mapping
}
}
}
這裡的
LoginAction extends Action 說明 struts 每有和spring 耦合
看一下applicationContext
<bean id=
<bean name=
<property name=
<ref local=
</property>
</bean>
</beans>
這裡 name=
還要為 LoginAction 提供必要的setXXX方法
[
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29075.html