1.实现产品列表的图文版和图片版的切换显示
2.显示产品描述时,去掉其中的html标签
3.完成显示产品大图的功能
a.获得大图的路径
b.单击显示大图,激发javascript事件,请求某个action跳到一个页面显示大图
4.购物车的需求与各种实现技术的分析
需求:
a.添加商品
b.删除商品
c.修改购买数量
d.付款功能
实现方案:
a.session
b.cookie+数据库
c.ejb有状态对象
5.实现多个浏览器共享同一个购物车的功能
思路:
a.将为用户第一次创建的session保存到map中,键是session id,值是:session
b.将第一此创建的session id以Cookie的形式保存到客户端
c.当客户端请求的时候,首先到map中根据id进行查找,若找到则将该session中的内容存 放到request域中一边共享
代码:
Session监听器


1 public class LocalSessionListener implements HttpSessionListener { 2 private static Map<String,HttpSession> sessions = new HashMap<String, HttpSession>(); 3 public void sessionCreated(HttpSessionEvent sessionEvent) { 4 System.out.println(sessionEvent.getSession().getId()); 5 sessions.put(sessionEvent.getSession().getId(), sessionEvent.getSession()); 6 } 7 8 public void sessionDestroyed(HttpSessionEvent sessionEvent) { 9 sessions.remove(sessionEvent.getSession().getId()); 10 } 11 /** 12 * 根据sessionId获取session 13 * @param sessionId 要获取的session的id 14 * @return 15 */ 16 public static HttpSession getSessionById(String sessionId){ 17 return sessions.get(sessionId); 18 } 19
}
action:


1 @Override 2 public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) 3 throws Exception { 4 String sessionId = request.getParameter("sessionId"); 5 if(LocalSessionListener.getSessionById(sessionId)==null){ 6 HttpSession session = request.getSession(); 7 session.setAttribute("time", new Date()); 8 }else { 9 HttpSession session = LocalSessionListener.getSessionById(sessionId); 10 request.setAttribute("out", session.getAttribute("time")); 11 } 12 return mapping.findForward("cart"); 13 }