?? useraction.java
字號:
package com.estore.web.action;
import java.util.List;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.MappingDispatchAction;
import com.estore.biz.UserBiz;
import com.estore.entity.*;
public class UserAction extends MappingDispatchAction{
//用戶登陸
public ActionForward login(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionForward forward = null;
UserBiz biz = new UserBiz();
User user=null;
try{
HttpSession session = request.getSession(false);
String username=request.getParameter("name");
String password = request.getParameter("password");
user = biz.findUserByName(username);
Cart cart = (Cart)session.getAttribute("cart");
if(user != null){
if(password.equals(user.getPassword())){
if(cart == null){
session.setAttribute("user",user);
forward=mapping.findForward("login");
}else{
session.setAttribute("user",user);
forward = mapping.findForward("loginbycart");
}
}else{
ActionErrors errors = new ActionErrors();
ActionMessage message = new ActionMessage("errors.password");
errors.add("message", message);
saveErrors(session, errors);
forward=mapping.findForward("errorpassword");
}
}else{
ActionErrors errors = new ActionErrors();
ActionMessage message = new ActionMessage("errors.nouser");
errors.add("message", message);
saveErrors(session, errors);
forward=mapping.findForward("register");
}
}catch(Exception e){
e.printStackTrace();
forward=mapping.findForward("error");
}
return forward;
}
//用戶注冊
public ActionForward register(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionForward forward = null;
UserBiz biz = new UserBiz();
try{
String name=request.getParameter("name");
String password = request.getParameter("password");
String address = request.getParameter("address");
String postCode= request.getParameter("postCode");
String homePhone= request.getParameter("homePhone");
String officePhone=request.getParameter("officePhone");
String cellPhone= request.getParameter("cellPhone");
String email=request.getParameter("email");
User user=new User();
user.setName(name);
user.setPassword(password);
user.setAddress(address);
user.setPostCode(postCode);
user.setCellPhone(cellPhone);
user.setHomePhone(homePhone);
user.setOfficePhone(officePhone);
user.setEmail(email);
biz.adduser(user);
forward=mapping.findForward("register");
}catch(Exception e){
e.printStackTrace();
forward=mapping.findForward("error");
}
return forward;
}
//退出
public ActionForward logout(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionForward forward = null;
User user=null;
try{
HttpSession session = request.getSession(false);
user=(User)session.getAttribute("user");
if(user!=null){
session.removeAttribute("user");
forward=mapping.findForward("logout");
}else
forward=mapping.findForward("list");
}catch(Exception e){
e.printStackTrace();
forward=mapping.findForward("error");
}
return forward;
}
public ActionForward listOrder(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionForward forward = null;
UserBiz biz = new UserBiz();
try{
//Integer id=Integer.valueOf(request.getParameter("uid"));
//if(id == null){
HttpSession session = request.getSession(false);
User user=(User)session.getAttribute("user");
Integer id = user.getUid();
//}
List<Order> orders = biz.findOrderByUserId(id);
request.setAttribute("orders", orders);
forward = mapping.findForward("listOrder");
}catch(Exception e){
e.printStackTrace();
forward = mapping.findForward("error");
}
return forward;
}
public ActionForward deleteOrder(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
ActionForward forward = null;
UserBiz biz = new UserBiz();
try{
Integer id = Integer.valueOf(request.getParameter("oid"));
biz.deleteOrderById(id);
forward = mapping.findForward("deleteOrder");
}catch(Exception e){
e.printStackTrace();
forward = mapping.findForward("error");
}
return forward;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -