⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginaction.java

📁 只做是单选题!数据库表有三张:EUser,EItem,Score
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.exam.controller;import com.exam.model.ExamService;import com.exam.model.LoginService;import com.exam.model.User;import java.sql.SQLException;import java.util.LinkedList;import java.util.List;import javax.ejb.ObjectNotFoundException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionForward;/** * * @author fyadmin */public class LoginAction extends org.apache.struts.action.Action {    /* forward name="success" path="" */    public ActionForward execute(ActionMapping mapping, ActionForm form,            HttpServletRequest request,            HttpServletResponse response) throws SQLException, ObjectNotFoundException {        List errorMsgs = new LinkedList();        ExamService es = new ExamService();        HttpSession session = request.getSession();        try {            String userName = request.getParameter("username");            String passWord = request.getParameter("password");            if (userName.length() == 0) {                errorMsgs.add("请填写用户名");            }            if (passWord.length() == 0) {                errorMsgs.add("请填写密码");            }            if (userName.length() != 0 && passWord.length() != 0) {                LoginService loginSvc = new LoginService();                User user = loginSvc.getRetriver(userName, passWord);                if (user == null) {                    errorMsgs.add("请填写正确的用户名和密码");                } else {                    session.setAttribute("question_list", es.getAllExam());                    session.setAttribute("uid", user.getUID());                    return mapping.findForward("success");                }            }            if (!errorMsgs.isEmpty()) {                request.setAttribute("errorMsgs", errorMsgs);                return mapping.findForward("error");            }        } catch (RuntimeException e) {            e.printStackTrace(System.err);            errorMsgs.add(e.getMessage());        }        return mapping.findForward("error");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -