空指针异常问题(springMVC)

qq_42765496 qq_42765496 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
本人新人一枚,在学springmvc,报空指针异常能帮忙看看嘛
public class LoginController extends  SimpleFormController{
private String showUser;
private String errPage;
public String getErrPage() {
return errPage;
}
public void setErrPage(String errPage) {
this.errPage = errPage;
}
public LoginController(){
setCommandClass(User.class);
}
protected ModelAndView onSubmit(Object command,BindException exception)throws Exception{
User user = (User) command;
LoginDao log = new LoginDao();
if(user.getUser().equals("")){
return new ModelAndView(getErrPage(),"error","用户名不能为空!");
}
if(user.getPwd().equals("")){
return new ModelAndView(errPage,"error","密码不能为空!");
}
if(user.getPwd().length()<6){
return new ModelAndView(errPage,"error","密码不能少于6位!");
}
if(log.isExist(user.getUser(),user.getPwd())){
return new ModelAndView(getShowUser(),"user",user);
}
return new ModelAndView(errPage,"error","账号或密码错误!");

}

public class LoginDao {
public boolean isExist(String username,String password){
Connection conn=DBManager.getConn();
boolean result=false;
String sql="select * from login where name=? and password=?";
PreparedStatement ps=null;
ResultSet rs=null;
try {
ps=conn.prepareStatement(sql);
ps.setString(1, username);
ps.setString(2, password);
rs=ps.executeQuery();
if(rs.next()){
result=true;
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBManager.closeAll(rs, ps, conn);
}
return result;
}
}

前面几个if判断都能执行并跳转但一运行到这个方法就报错
该方法在测试类中是可以运行的
public class Test {
public static void main(String[] args) {
LoginDao log = new LoginDao();
System.out.println(log.isExist("zhangsan","123456"));
}
}




是不是还要找spring-servlet中配置?还是别的
...全文

相关推荐

评论 16
收藏 已收藏
分享
返回顶部
qq_42765496
Web 开发 81,108 成员 341,721 内容