LoginAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:1k
- package classmate;
- import org.apache.struts.action.Action;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionMessages;
- import org.apache.struts.action.ActionMessage;
- import javax.servlet.ServletContext;
- import javax.sql.DataSource;
- import javax.servlet.http.*;
- public final class LoginAction extends Action{
- public ActionForward execute(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws Exception {
-
-
- UserForm userform = (UserForm) form;
- String name = userform.getName();
- String psw = userform.getPsw();
-
- ServletContext context = servlet.getServletContext();
- DataSource dataSource = (DataSource)context.getAttribute("oracleDB1");
-
- DBUser dbuser = new DBUser(dataSource);
- HttpSession session = request.getSession();
-
- if (!dbuser.checkUser(name,psw)) {
- ActionMessages errors = new ActionMessages();
- errors.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("label.deny"));
-
- if (!errors.isEmpty()) {
- saveErrors(request, errors);
- }
- return mapping.findForward("failed"); //登陆失败
- }
- else{
- return (mapping.findForward("successed"));//登陆成功
- }
- }
- }