package com.bjpowernode.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* 登录Action
* 负责取得表单数据、调用业务逻辑、返回转向信息
*
* @author Administrator
*
*/
public class LoginAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginActionForm laf = (LoginActionForm)form;
String username = laf.getUsername();
String password = laf.getPassword();
UserManager userManager = new UserManager();
try {
userManager.login(username, password);
request.getSession().setAttribute("username", username);
return mapping.findForward("success");
}catch(UserNotFoundException e) {
e.printStackTrace();
request.setAttribute("msg", "用户不能找到,用户名称=【" + username + "】");
}catch(PasswordErrorException e) {
e.printStackTrace();
request.setAttribute("msg", "密码错误");
}
return mapping.getInputForward();
}
}
3.Struts的<action input=""></action>:Action
最新推荐文章于 2022-03-21 15:29:36 发布
本文介绍了一个使用Struts框架实现的登录Action类。该类继承自Struts的Action基类,实现了execute方法来处理用户的登录请求。具体流程包括从表单获取用户名和密码,调用UserManager进行验证,并根据验证结果跳转到相应的页面。
摘要由CSDN通过智能技术生成