package controller;
import java.util.HashMap;
import java.util.Map;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import model.UserInfoBean;import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;/**
* 用户登录控制器
*
* @author Administrator
*
*/
public class LoginController implements Controller{
//成功页面,它的值在 appliationContext.xml中通过配置被注入
private String successPage;
//失败页面,它的值在 applicationContext.xml中通过配置被注入
private String errorPage;
//从 Controller 接口实现方法
public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespones)throws Exception{
//取得用户名和密码
String username = request.getParameter("username");
String password = request.getParameter("password");
//消息
String message = null;
//简单的空值验证
if(username ==null&password ==null&username.trim().equals("")&password.trim().equals("")){
//本质上是通过request.setAtrribute将msg消息封装在request对象中
message = "用户名或者密码为空";
Map<String,String>model = new HashMap<String,String>();
model.put("msg",message);
//跳转到错误页面
return new ModelAndView(getErrorPage(),model);
}
//UserInfoBean是模型层,它模拟了数据库,exisitUser 方法判断用户名是否存在
if(!UserInfoBean.exisitUser(username)){
//用户名不存在
message = username + "不存在!";
Map<String,String>model = new HashMap<String,String>();
model.put("msg",message);
//跳转到错误页面
return new ModelAndView(getErrorPage(),model);
}
//UserInfoBean是模型层,它模拟了数据库,confirmPassword方法判断//密码是否正确,//前提是用户名已经存在
if(!UserInfoBean.confirmPassword(username,password)){
//密码不正确
message = username + "的密码不正确";
Map<String,String>model = new HashMap<String,String>();
model.put("msg",message);
//跳转到错误页面
return new ModelAndView(getErrorPage(),model);
}
else{
//用户名存在,且密码正确
Map<String,String>model = new HashMap<String,String>();
model.put("username",username);
//跳转到成功页面
return new ModelAndView(getSuccessPage(),model);
}
}
//--------getter和setter方法区---------
public String getErrorPage(){
return errorPage;
}
public void setErrorPage(String errorPage){
this.errorPage = errorPage;
}
public String getSuccessPage(){
return successPage;
}
public void setSuccessPage(String successPage){
this.successPage = successPage;
}
}
import java.util.HashMap;
import java.util.Map;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import model.UserInfoBean;import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;/**
* 用户登录控制器
*
* @author Administrator
*
*/
public class LoginController implements Controller{
//成功页面,它的值在 appliationContext.xml中通过配置被注入
private String successPage;
//失败页面,它的值在 applicationContext.xml中通过配置被注入
private String errorPage;
//从 Controller 接口实现方法
public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespones)throws Exception{
//取得用户名和密码
String username = request.getParameter("username");
String password = request.getParameter("password");
//消息
String message = null;
//简单的空值验证
if(username ==null&password ==null&username.trim().equals("")&password.trim().equals("")){
//本质上是通过request.setAtrribute将msg消息封装在request对象中
message = "用户名或者密码为空";
Map<String,String>model = new HashMap<String,String>();
model.put("msg",message);
//跳转到错误页面
return new ModelAndView(getErrorPage(),model);
}
//UserInfoBean是模型层,它模拟了数据库,exisitUser 方法判断用户名是否存在
if(!UserInfoBean.exisitUser(username)){
//用户名不存在
message = username + "不存在!";
Map<String,String>model = new HashMap<String,String>();
model.put("msg",message);
//跳转到错误页面
return new ModelAndView(getErrorPage(),model);
}
//UserInfoBean是模型层,它模拟了数据库,confirmPassword方法判断//密码是否正确,//前提是用户名已经存在
if(!UserInfoBean.confirmPassword(username,password)){
//密码不正确
message = username + "的密码不正确";
Map<String,String>model = new HashMap<String,String>();
model.put("msg",message);
//跳转到错误页面
return new ModelAndView(getErrorPage(),model);
}
else{
//用户名存在,且密码正确
Map<String,String>model = new HashMap<String,String>();
model.put("username",username);
//跳转到成功页面
return new ModelAndView(getSuccessPage(),model);
}
}
//--------getter和setter方法区---------
public String getErrorPage(){
return errorPage;
}
public void setErrorPage(String errorPage){
this.errorPage = errorPage;
}
public String getSuccessPage(){
return successPage;
}
public void setSuccessPage(String successPage){
this.successPage = successPage;
}
}
解决方案 »
- 咨询两个问题的处理方式
- 高分求解...SWFupload显示不出来进度条!!
- 请假一个hibernate多对一的问题
- JBuilder 开发的struts 程序打成war包时都需要把什么打进去?
- struts图片显示问题
- 救命!不知道为什么!jsp配置老是失败!谢谢了
- 怎么把struts-action的转发页面转发到某个iframe里?
- hibernate 为什么只能调用master数据库的存过程
- (我的分快没了)大家帮忙看看吧,我捣鼓一天了,筋疲力尽!!!为什么这个Struts始终徘徊在表单验证这里,不再往下走了,似乎Action的exce
- struts 在tomcat下可以使用,但在resin 中却发生错误! 各位高手请进!
- 严重: Exception starting filter struts2
- 看见此贴的。各位大虾们、帮帮吧。小弟感激不尽
还有。要是你的username或者是password为空的话,
有没有报空指针异常呢?我很好奇啊。呵呵。
import model.UserInfoBean;这一行报错了,说:the import model can not be resolved;
public class LoginController implements 这一行报错了,说:The type LoginController must implement the inherited abstract method Controller.handleRequest(HttpServletRequest, HttpServletResponse)public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespones)throws Exception 这一行报错了,说:Syntax error on token "HttpServletRespones", VariableDeclaratorId expected after this tokenif(!UserInfoBean.exisitUser(username)) 这一行报错了,说:String username - controller.LoginController.handleRequest(HttpServletRequest)if(!UserInfoBean.confirmPassword(username,password)) 这一行报错了,说:The method confirmPassword(String, String) is undefined for the type UserInfoBean
public class LoginController implements 这一行报错了,说:The type LoginController must implement the inherited abstract method Controller.handleRequest(HttpServletRequest, HttpServletResponse)public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespones)throws Exception 这一行报错了,说:Syntax error on token "HttpServletRespones", VariableDeclaratorId expected after this tokenif(!UserInfoBean.exisitUser(username)) 这一行报错了,说:String username - controller.LoginController.handleRequest(HttpServletRequest)if(!UserInfoBean.confirmPassword(username,password)) 这一行报错了,说:The method confirmPassword(String, String) is undefined for the type UserInfoBean
public class LoginController implements 这一行报错了,说:The type LoginController must implement the inherited abstract method Controller.handleRequest(HttpServletRequest, HttpServletResponse)public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespones)throws Exception 这一行报错了,说:Syntax error on token "HttpServletRespones", VariableDeclaratorId expected after this tokenif(!UserInfoBean.exisitUser(username)) 这一行报错了,说:String username - controller.LoginController.handleRequest(HttpServletRequest)if(!UserInfoBean.confirmPassword(username,password)) 这一行报错了,说:The method confirmPassword(String, String) is undefined for the type UserInfoBean
model.UserInfoBean没这东西
其他的呢按意思翻译
应该你是少了一些东西
仔细看看吧
如果都改好了 还是不行 就REBUILD下
选择project-->clean后,问题得到解决。如果还不能解决,可以尝试删掉import,
然后一个一个的手动导入【alt+/】唉,这还是网上找的