问题描述
找了很久都说是取不到值下面发代码-----------------------------------------------------------------------------------------------------------------------------packagecn.xp.Action;importcn.xp.Dao.UserDao;importcn.xp.Entity.Users;importcn.xp.impl.UserDaoImpl1;importcom.opensymphony.xwork2.ActionSupport;publicclassActionextendsActionSupport{privateStringuserName;//用户名privateStringpassword;//密码publicStringgetUserName(){returnuserName;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicvoidsetUserName(StringuserName){this.userName=userName;}@OverridepublicStringexecute()throwsException{UserDaouserdao=newUserDaoImpl1();Usersusers=userdao.login(userName);System.out.println(users.getName());if(userName.equals(users.getName())&&password.equals(users.getPassword())){return"success";}return"failure";}}-----------------------------------------------------------------------------------------------------------------------------报错显示users取不到值,弄了好久也没找出来,在线等,需要其他代码回复说明就行,谢谢
解决方案
解决方案二:
这个应该要把userdao的代码贴出来吧
解决方案三:
楼上正解userName如果能够获取到的话userdao才是关键
解决方案四:
是前台users取不到值还是后台取不到值?按你描述应该是前台取不到users,这个就对了,应该把privateUsersusers提到Action里,然后写上get/set方法还有Action名起的太特殊了,楼主可以考虑换个
解决方案五:
引用楼主qq_24247091的回复:
找了很久都说是取不到值下面发代码-----------------------------------------------------------------------------------------------------------------------------packagecn.xp.Action;importcn.xp.Dao.UserDao;importcn.xp.Entity.Users;importcn.xp.impl.UserDaoImpl1;importcom.opensymphony.xwork2.ActionSupport;publicclassActionextendsActionSupport{privateStringuserName;//用户名privateStringpassword;//密码publicStringgetUserName(){returnuserName;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicvoidsetUserName(StringuserName){this.userName=userName;}@OverridepublicStringexecute()throwsException{UserDaouserdao=newUserDaoImpl1();Usersusers=userdao.login(userName);System.out.println(users.getName());if(userName.equals(users.getName())&&password.equals(users.getPassword())){return"success";}return"failure";}}-----------------------------------------------------------------------------------------------------------------------------报错显示users取不到值,弄了好久也没找出来,在线等,需要其他代码回复说明就行,谢谢
packagecn.xp.Dao;importcn.xp.Entity.Users;publicinterfaceUserDao{publicUserslogin(StringUsername);}谢谢
解决方案六:
引用2楼heyzayz的回复:
楼上正解userName如果能够获取到的话userdao才是关键
packagecn.xp.Dao;importcn.xp.Entity.Users;publicinterfaceUserDao{publicUserslogin(StringUsername);}谢谢,你看看
解决方案七:
引用3楼shixitong的回复:
是前台users取不到值还是后台取不到值?按你描述应该是前台取不到users,这个就对了,应该把privateUsersusers提到Action里,然后写上get/set方法还有Action名起的太特殊了,楼主可以考虑换个
packagecn.xp.Dao;importcn.xp.Entity.Users;publicinterfaceUserDao{publicUserslogin(StringUsername);}谢谢你看看
解决方案八:
引用5楼qq_24247091的回复:
Quote: 引用2楼heyzayz的回复:
楼上正解userName如果能够获取到的话userdao才是关键packagecn.xp.Dao;importcn.xp.Entity.Users;publicinterfaceUserDao{publicUserslogin(StringUsername);}谢谢,你看看
看接口没用啊...你debug看看1.userName能不能获取2.userdao.login(userName);能不能拿到user3.jsp有没用问题第三个可能性不大第二个最大
解决方案九:
启动debug模式1.先确定是否可以进入这个Action,能则首先排除提交表单路径问题,看2.不能,则先查看表单提交路径2.单步调试查看userName是否有值,有则看3,没有则查看是否是表单控件ID与Action不一致3.单步调试查看拿到的Users对象是否注入了值