网上购物系统

源代码在线查看: header.java

软件大小: 14917 K
上传用户: wg204wg
关键词: 网上购物
下载地址: 免注册下载 普通下载 VIP

相关代码

				/**
				  * @(#)tarena.action.Header.java  2008-10-31  
				  * Copy Right Information	: Tarena
				  * Project					: xindou
				  * JDK version used		: jdk1.6.4
				  * Comments				: 网页头。
				  * Version					: 1.0
				  * Sr	Date		Modified By		Why & What is modified
				  * 1.	2008-10-31 	小猪     		新建
				  **/
				package tarena.action;
				
				import java.util.Vector;
				
				import javax.servlet.http.Cookie;
				import javax.servlet.http.HttpServletRequest;
				import javax.servlet.http.HttpServletResponse;
				
				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 tarena.dao.CategoryDAO;
				import tarena.dao.UserDAO;
				import tarena.data.AbractCategory;
				import tarena.global.CookieOperate;
				import tarena.global.PublicParameter;
				
				 /**
				 * 网页头。显示logo,菜单等。
				 * 2008-10-31
				 * @author		达内科技[Tarena Training Group]
				 * @version	1.0
				 * @since		JDK1.6(建议) 
				 */
				public class Header extends Action {
				
					@Override
					public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
						//1.获取客户端cookie
						//2.获取用户是否登陆的cookie,此处需要检测该cookie的用户是否为注册用户
						//3.保存cookie到requestScope,保存名称为username
						//4.查询所有分类,保存名称为categorys
						//5.查询顶级分类,保存名称为rootcategory
						//6.保存到request
						//7.定向到header
						Cookie cookie = CookieOperate.FindCookie(PublicParameter.cookie_user, request.getCookies());
						if(cookie!=null){
							//System.out.println(cookie.getValue()+"\nage:"+cookie.getMaxAge());
							UserDAO userDAO = new UserDAO();
							if(userDAO.isRegisterUser(cookie.getValue()))
								request.setAttribute("username", cookie.getValue());
							else{
								CookieOperate.DeleteCookie(cookie, response);
								cookie.setMaxAge(0);
								response.addCookie(cookie);
								//System.out.println("come delete cookie");
							}
						}
						CategoryDAO dao = new CategoryDAO();
						Vector categorys = dao.ListCategory(0, 0,false);
						Vector rootCategorys = dao.ListTopCategory();
						request.setAttribute("categorys", categorys);
						request.setAttribute("rootcategorys", rootCategorys);
						return mapping.findForward("header");
					}
				}
							

相关资源