《课程设计-电子商务平台 部分代码》由会员分享,可在线阅读,更多相关《课程设计-电子商务平台 部分代码(13页珍藏版)》请在金锄头文库上搜索。
1、部分代码展示如下:图片验证码生成代码如下(CheckCodeAciton):public class CheckCodeAction extends Actionpublic ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)response.setContentType(image/jpeg);/ 图片的内存映像BufferedImage image=new BufferedImage(60,25,Buffere
2、dImage.TYPE_INT_RGB);/ 获得画笔对象Graphics g = image.getGraphics();Random r = new Random();g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255);g.fillRect(0, 0, 60, 25);g.setColor(new Color(0,0,0);String str = ;for(int i=0;i=pages)bookListForm.setPage(pages);page=pages;if(pagebooks = DAOFact
3、ory.getBookDAO().findByParentId(scc,beginIndex, size);request.getSession().setAttribute(counts, counts);if(pages=0)pages = 1;购物车核心代码 CartService:public class CartService private Map store = new HashMap();public CartService()public static CartService getInstance(HttpSession session)CartService cart =
4、 (CartService)session.getAttribute(cart);if(cart = null)cart = new CartService();session.setAttribute(cart, cart);return cart;public void add(Integer id)if(store.containsKey(id)CartItem item = store.get(id);item.setNum(item.getNum()+1);elseBook book = DAOFactory.getBookDAO().findById(id);CartItem it
5、em = new CartItem();item.setPro(book);store.put(id,item);public void delete(Integer id)if(store.containsKey(id)CartItem item = store.get(id);item.setBuy(false);public void delete(boolean flag)Set set = store.entrySet();Iterator it = set.iterator();while(it.hasNext()Map.Entry entry = (Map.Entry)it.ne
6、xt();CartItem item = (CartItem)entry.getValue();if(item.isBuy()=flag)it.remove();public void recovery(Integer id)if(store.containsKey(id)CartItem item = store.get(id);item.setBuy(true);public double cost(boolean flag)double sum = 0;List items = getItems(true);for(int i=0;i getItems(boolean isbuy)Lis
7、t items = new ArrayList();Set set = store.entrySet();Iterator it = set.iterator();while(it.hasNext()Map.Entry entry = (Map.Entry)it.next();CartItem item = (CartItem)entry.getValue();if(item.isBuy()=isbuy)items.add(item);return items;Ajax异步请求代码如下:$(function() $(#address).change(function()if($(this).h
8、tml!=填写新地址)$.ajax(url:/select.do,type:post,data:$(#address).serialize(),dataType:json,success:function(data,status)$(#receiveName).val(data.receive_name);$(#fullAddress).val(data.full_address);$(#postalCode).val(data.postal_code);$(#phone).val(data.phone);$(#mobile).val(data.mobile);,error:function(
9、xhr,textStatus,errorThrown)alert(xhr.status););););ManagerLoginAction代码如下:public class ManagerLoginAction extends Actionpublic ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)ManagerLoginForm managerForm = (ManagerLoginForm)form;Str
10、ing managername = managerForm.getManagername();String password = managerForm.getPassword();if(managername.trim().equals(sunjinfu) & password.trim().equals(sunluoyang1987)request.getSession().setAttribute(manager_error, null);request.getSession().setAttribute(manager, success);return mapping.findForw
11、ard(index);elserequest.getSession().setAttribute(manager_error, 管理员登录验证失败);return mapping.findForward(manager_login);部分页面代码如下:function collapse_change(menucount) if ($(menu_ + menucount).style.display = none) $(menu_ + menucount).style.display = ;$(menuimg_ + menucount).src = css/main/menu_reduce.gi
12、f; else $(menu_ + menucount).style.display = none;$(menuimg_ + menucount).src = css/main/menu_add.gif;var menus = new Array(g1,g2,g3,g4);function togglemenu(id) for (i = 0; i SearchUserAction代码如下:public class SearchUserAction extends Actionpublic ActionForward execute(ActionMapping mapping,ActionFor
13、m form,HttpServletRequest request,HttpServletResponse response)UserManageForm manageForm = (UserManageForm)form;String email_id = manageForm.getEmail_id();User user = null;String reg1 = .1,30w2,10.2,10;String reg2 = 0-9+$;UserDAOImpl userDAO = (UserDAOImpl) DAOFactory.getUserDAO();if(email_id.matche
14、s(reg1)user = userDAO.findByEmail(email_id.trim();else if(email_id.matches(reg2)user = userDAO.findById(Integer.parseInt(email_id.trim();request.getSession().setAttribute(user_error, null);manageForm.setUser(user);return mapping.findForward(user_detail);/ elserequest.getSession().setAttribute(user_e
15、rror, 您的输入有误!);return mapping.findForward(user_list);Ajax级联动态下拉框代码如下:$(function()$(#superCategory).change(function()if($(this).html!=选择分类)$.ajax(url:/getcategory.do,type:post,data:$(#superCategory).serialize(),dataType:json,success:function(data,status)document.getElementById(category).innerHTML=;for(var i=0;i/getsubcategory.do,type:post,data:$(#category).serialize(),dataType:json,success:function(data,status)$(#whichCategory).val(data.name);,error:function(xhr,textStatus,errorThrown)alert(xhr.status););