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

📄 acountaction.java

📁 网站计数器 在通常情况下
💻 JAVA
字号:
package com.action;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.actionForm.AcountForm;
import org.apache.struts.actions.DispatchAction;
import com.tool.Chinese;
import com.dao.CountDao;
import javax.servlet.http.HttpSession;
import com.tool.ManagerList;
import java.util.Vector;
import java.util.Enumeration;
import com.tool.ManagerTrace;

public class AcountAction extends DispatchAction {
    private Chinese chinese = null;
    private CountDao dao = null;
    public AcountAction() {
        chinese = new Chinese();
        dao = new CountDao();
    }

//==============================================================================
    public ActionForward checkAcount(ActionMapping mapping, ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) {
        String account = Chinese.toChinese(request.getParameter("account"));
       System.out.println(dao.selectOneAcount(account));
        //-----------------------------------------------------
        boolean flag = true;
        HttpSession session = request.getSession();
        ManagerList manger = ManagerList.getInstance();
        Vector vc = manger.getList();
        AcountForm accountFrom = dao.selectOneAcount(account);
        if (!vc.isEmpty() && vc != null) {
            Enumeration en = vc.elements();
            while (en.hasMoreElements()) {
                AcountForm admin = (AcountForm) en.nextElement();
                if (admin.getAccount().equals(account)) {
                    flag = false; //管理员在线
                }
            }
        } else {
            flag = true;
        }
//==============================================================================
        if (dao.selectOneAcount(account) == null) {
     request.setAttribute("success", "您输入的账号和密码不存在!!!");

   }
   else if (!dao.selectOneAcount(account).getPassword().equals(Chinese.toChinese(request.getParameter("password")))) {
     request.setAttribute("success", "您输入的密码不存在!!!");

   }
   else if (!flag) {
     request.setAttribute("success", "您输入的用户名正在使用中!!!");

   }
   else {
     dao.addCount(account);
     int id = accountFrom.getId();
     ManagerTrace managerTrace = new ManagerTrace();
     managerTrace.setId(id);
     manger.addManager(accountFrom);
     session.setAttribute("managerTrace", managerTrace);
     session.setAttribute("id", String.valueOf(id));
     request.setAttribute("accountFrom", accountFrom);

   }  return mapping.findForward("checkAcount");
    }

//==============================================================================
    public ActionForward insertAcount(ActionMapping mapping, ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response) {
        AcountForm acountForm = (AcountForm) form;
        System.out.println("mr="+chinese.toChinese(acountForm.getAccount()));
        if (dao.selectOneAcount(chinese.toChinese(acountForm.getAccount())) == null) {
            acountForm.setAccount(chinese.toChinese(acountForm.getAccount()));
            acountForm.setAge(acountForm.getAge());
            acountForm.setBorn(chinese.toChinese(acountForm.getBorn()));
            acountForm.setName(chinese.toChinese(acountForm.getName()));
            acountForm.setPassword(chinese.toChinese(acountForm.getPassword()));
            acountForm.setProfession(chinese.toChinese(acountForm.getProfession()));
            acountForm.setSex(chinese.toChinese(acountForm.getSex()));
            acountForm.setNumber(1);
            dao.insertCount(acountForm);
            request.setAttribute("success", "您注册成功!!!");
        } else {
            request.setAttribute("success", "该账号已经存在,请重新输入!!!");
        }
        return mapping.findForward("insertAcount");
    }
}

⌨️ 快捷键说明

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