java
1protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 2 HttpSession session = request.getSession(); 3 try { 4 //選択された配送方法IDを取得 5 int inputDeliveryMethodId = Integer.parseInt(request.getParameter("delivery_method_id")); 6 //選択されたIDをもとに配送方法Beansを取得 7 DeliveryMethodDataBeans userSelectDMB = DeliveryMethodDAO.getDeliveryMethodDataBeansByID(inputDeliveryMethodId); 8 //買い物かご 9 ArrayList<ItemDataBeans> cartIDBList = (ArrayList<ItemDataBeans>) session.getAttribute("cart"); 10 //合計金額 11 int totalPrice = EcHelper.getTotalItemPrice(cartIDBList); 12 13 BuyDataBeans bdb = new BuyDataBeans(); 14 bdb.setUserId((int) session.getAttribute("userId")); 15 bdb.setTotalPrice(totalPrice); 16 bdb.setDelivertMethodId(userSelectDMB.getId()); 17//購入確定で利用 18 session.setAttribute("bdb", bdb); 19 request.getRequestDispatcher(EcHelper.BUY_CONFIRM_PAGE).forward(request, response); 20 } catch (Exception e) { 21 e.printStackTrace(); 22 session.setAttribute("errorMessage", e.toString()); 23 response.sendRedirect("Error"); 24 } 25 } 26 27}
java
1DeliveryMethodDataBeansのBeans 2public class DeliveryMethodDataBeans implements Serializable { 3 private int id; 4 private String name; 5 private int price; 6 7 8 public int getId() { 9 return id; 10 } 11 public void setId(int id) { 12 this.id = id; 13 } 14 public String getName() { 15 return name; 16 } 17 public void setName(String name) { 18 this.name = name; 19 } 20 public int getPrice() { 21 return price; 22 } 23 public void setPrice(int price) { 24 this.price = price; 25 } 26}
java
1BuyDataBeansのbeans 2public class BuyDataBeans implements Serializable { 3 private int id; 4 private int userId; 5 private int totalPrice; 6 private int delivertMethodId; 7 private Date buyDate; 8 9 private String deliveryMethodName; 10 private int deliveryMethodPrice; 11 12 13 public int getId() { 14 return id; 15 } 16 public void setId(int id) { 17 this.id = id; 18 } 19 public int getUserId() { 20 return userId; 21 } 22 public void setUserId(int userId) { 23 this.userId = userId; 24 } 25 public int getTotalPrice() { 26 return totalPrice; 27 } 28 public void setTotalPrice(int totalPrice) { 29 this.totalPrice = totalPrice; 30 } 31 32 33 public int getDelivertMethodId() { 34 return delivertMethodId; 35 } 36 public void setDelivertMethodId(int delivertMethodId) { 37 this.delivertMethodId = delivertMethodId; 38 } 39 public Date getBuyDate() { 40 return buyDate; 41 } 42 public void setBuyDate(Date buyDate) { 43 this.buyDate = buyDate; 44 } 45 public String getDeliveryMethodName() { 46 return deliveryMethodName; 47 } 48 public void setDeliveryMethodName(String deliveryMethodName) { 49 this.deliveryMethodName = deliveryMethodName; 50 } 51 52 public String getFormatDate() { 53 SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH時mm分"); 54 return sdf.format(buyDate); 55 } 56 public String getFormatTotalPrice() { 57 return String.format("%,d", this.totalPrice); 58 } 59 public int getDeliveryMethodPrice() { 60 return deliveryMethodPrice; 61 } 62 public void setDeliveryMethodPrice(int deliveryMethodPrice) { 63 this.deliveryMethodPrice = deliveryMethodPrice; 64 } 65 66 67} 68
最後の行のbdbのインスタンスにつめてsessionを使おうと思っているのですがdeliveryMethodName、deliveryMethodPriceの値が入りません
bdbのインスタンスの中にuserSelectDMBを入れたいです
userSelectDMBのインスタンスにはid,name,priceが入っていて取れています。
その値をbdbインスタンスの deliveryMethodName、deliveryMethodPrice、に
deliveryMethodName、deliveryMethodPriceに値userSelectDMBのインスタンスの値を移したいです
userSelectDMBで取れてるname→ bdbのdeliveryMethodName
userSelectDMBで取れてるprice→ bdbのdeliveryMethodPrice
を移せたら正解です
方法、どこがおかしいのかが分からないです。
恐れ入りますがどこが間違っているか教えていただけたら幸いです。
他にも情報が必要でしたら編集いたします
userSelectDMBではDeliveryMethodDataBeansからid.name.priceは取れています
bdbではdeliveryMethodName、deliveryMethodPriceの値がnull,0になっています
deliveryMethodName、deliveryMethodPriceの値を取得したいです
回答1件
あなたの回答
tips
プレビュー