📄 loginaction.java
字号:
package com.set.home.struts.action;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.set.appframe.data.GenericValueObject;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.set.appframe.exception.SystemException;
import com.set.appframe.web.MyBaseAction;
import com.set.home.business.NoticeMgr;
import com.set.home.business.ProductMgr;
import com.set.system.business.AccountMgr;
import com.set.system.model.UsersVO;
public class LoginAction extends MyBaseAction {
public ActionForward search(ActionMapping mapping, ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws SystemException {
String key="";
if(request.getParameter("key")!=null){
key=request.getParameter("key");
}
List productTop10=null;
List noticeResult=null;
List product=null;
ProductMgr pmgr=(ProductMgr)getBean("ProductMgr");
NoticeMgr nmgr=(NoticeMgr)getBean("NoticeMgr");
productTop10=pmgr.searchTop10();
noticeResult=nmgr.searchLast();
request.setAttribute("productTop10", productTop10);
request.setAttribute("noticeResult", noticeResult);
if(key.equals("")){
product=pmgr.search();
request.setAttribute("product", product);
return mapping.findForward("search");
}
if(key.equals("top")){
product=pmgr.searchTop10();
request.setAttribute("product", product);
return mapping.findForward("searchtop");
}
if(key.equals("newlevel")){
product=pmgr.searchNew10();
request.setAttribute("product", product);
return mapping.findForward("searchnew");
}
return null;
}
public ActionForward load(ActionMapping mapping, ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws ServletException, IOException, SystemException {
String username="";
String password="";
UsersVO vo=new UsersVO();
GenericValueObject gvo=new GenericValueObject();
username=request.getParameter("USERNAME");
password=request.getParameter("PASSWORD");
vo.setUsername(username);
vo.setPassword(password);
if (!checkVerifyCode(request)) { // 验证码错误
request.setAttribute("error1", "1");
}else{
try {
AccountMgr mgr=(AccountMgr)getBean("AccountMgr");
gvo=mgr.checkUser(vo);
if (gvo!=null){
request.getSession().setAttribute("USERNAME", gvo.getItemString("USERNAME"));
request.getSession().setAttribute("ID", gvo.getItemString("ID"));
request.getSession().setAttribute("PASSWORD", gvo.getItemString("PASSWORD"));
request.getSession().setAttribute("ROLE", gvo.getItemString("ROLE"));
}
request.setAttribute("users",gvo);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return this.search(mapping, form, request, response);
}
protected boolean checkVerifyCode(HttpServletRequest request) {
boolean f = false;
HttpSession session = request.getSession();
String rand = (String) session.getAttribute("rand");
String input = String.valueOf(request.getParameter("VERIFYCODE"));
return input.equals(rand);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -