[Burichan] [Futaba] [Gurochan] [Photon] - [Home]

[Return]
Reply mode
Name
Link
Subject
Comment
File
Password (for post and file deletion)
Leave empty (spam trap):
  • Supported file types are: GIF, JPG, PNG
  • Maximum file size allowed is 1000 KB.
  • Images greater than 200x200 pixels will be thumbnailed.

File: 1208233340132.jpg -(29128 B, 570x327) Thumbnail displayed, click image for full size.
29128 No.1   [Reply]

<table>
<tr>

	<td colspan="2">
<% String message = (String)request.getAttribute("message");
if (message != null)out.println(message); %>
</td></tr>

<tr><td><h3>Your Cart</h3></td></tr>
<%
ArrayList theCart = new ArrayList();
theCart = (ArrayList)session.getAttribute("cart");
//theCart = (ArrayList)request.getAttribute("cart");
if (theCart != null){

int number = 0;
if( theCart.size() > 0){
number = theCart.size();
}
for (int c=0; c < number; c++)
{
ProductFormBean product = (ProductFormBean)theCart.get(c); //elementAt(c);
out.println("<tr><td>"+product.getProductId()+"</td><td>"
+product.getDescription()+"</td><td>"
+product.getQuantity()+"</td></tr>");
}

}
else{

out.println("Nothing returned");

}
%>
</table>

>> No.2  

ArrayList theCart = new ArrayList();

    if (session.getAttribute("cart") != null){
theCart = (ArrayList)session.getAttribute("cart");
}
beans.ProductFormBean theBean = (ProductFormBean)form;
managers.ProductManager manager = new managers.ProductManager();
    if (theBean.getProductId() == 0) {
request.setAttribute("message", "Product Id is required");
nextPage = mapping.findForward("failure");
}
else if (theBean.getQuantity() == 0) {
request.setAttribute("message", "Quantity is required");
nextPage = mapping.findForward("failure");
}
    else{
try{
theBean = manager.find(theBean);
if (theBean == null){
nextPage = mapping.findForward("failure");
request.setAttribute("message", "Error locating product");
}
else{
request.setAttribute("message", "Product Added to Cart");
theCart.add(theBean);
theCart.add(theBean);
//request.setAttribute("cart", theCart);
session.setAttribute("cart",theCart);

nextPage = mapping.findForward("success");
}
}
catch (Exception e){
request.setAttribute("message", e+" "+"exception error");
nextPage = mapping.findForward("failure");
}

// request.setAttribute("cart", theBean);

    }
return nextPage;
>> No.3  
public ProductFormBean find (ProductFormBean theBean) throws Exception
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

ProductFormBean bean = (ProductFormBean)session.get(ProductFormBean.class, theBean.getProductId());

session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
return bean;
}
>> No.4  

package actions;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import beans.*;
import java.util.*;

public final class AddToCartServlet extends Action
{

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ActionForward nextPage = null;
HttpSession session = request.getSession();

ArrayList theCart = new ArrayList();
if (session.getAttribute("cart") != null){
theCart = (ArrayList)session.getAttribute("cart");
}
beans.ProductFormBean theBean = (ProductFormBean)form;
managers.ProductManager manager = new managers.ProductManager();
    if (theBean.getProductId() == 0) {
request.setAttribute("message", "Product Id is required");
nextPage = mapping.findForward("failure");
}
else if (theBean.getQuantity() == 0) {
request.setAttribute("message", "Quantity is required");
nextPage = mapping.findForward("failure");
}
else{
try{
theBean = manager.find(theBean);
if (theBean == null){
nextPage = mapping.findForward("failure");
request.setAttribute("message", "Error locating product");
}
else{
request.setAttribute("message", "Product Added to Cart");
theCart.add(theBean);
//request.setAttribute("cart", theCart);
totaller bob = new totaller();
String total = bob.total(theCart);
session.setAttribute("cart", theCart);
nextPage = mapping.findForward("success");
}
}
catch (Exception e){
request.setAttribute("message", e+" "+"exception error");
nextPage = mapping.findForward("failure");
}

// request.setAttribute("cart", theBean);

    }
return nextPage;
}

}



Delete Post []
Password