ssh2 登陆提交表单出现
空指针异常null
2010-1-28 14:15:25 org.apache.catalina.core.StandardWrapperValve invoke
严重:
Servlet.service() for servlet default threw exceptionjava.lang.NullPointerException at com.test.action.LoginAction.execute(LoginAction.java:48)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
下面是LoginAction
public class LoginAction extends ActionSupport {
private Users user;
private UsersService userService;
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
public UsersService getUserService() {
return userService;
}
public void setUserService(UsersService userService) {
this.userService = userService;
}
@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
System.out.println(user);
this.userService.login(user);
return SUCCESS;
}
------解决方案--------------------
------解决方案--------------------user是一个实例化的对象
你打印的是一个类,它打印出这个来应该是对的
System.out.println(user.userName); (如果这种写法不对的话换成System.out.println(user.getUserName()); )
这样应该就可以正确显示你的userName的值了
------解决方案--------------------
------解决方案--------------------是不是Spring配置文件中DAO没有实例化或者连库链接类没有注入进去?
------解决方案--------------------
<bean id="saveUsersActiom" class="com.test.action.SaveUsersAction">
<property name="usersService" ref="usersService"> </property>
</bean>
=====================================
错了,这一个先不要改,保持原样
------解决方案--------------------不是代码有错误,是你的逻辑有错误,
登陆之前,你先要到数据库中去除出user列表,然后 list.get(i)方法遍历,遍历出来的你进行封装,封装成User对象,进行判断:
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username.equals( user.getUserName()) && password .equals(user.getPassword() )