servlets - How to calculate the price with session? -
hi have problem servlets. read , know how use them don't know how calculate price.
this need do. hope u can me.
in html code need write form write username , pass in textfileds. when click on button sign in signinservlet.mk generate. servlet need create session keep username html code , sets cookie username. servlet generate “catalog.html” . page contains information products. each product showing picture of it, , next title, price, , button "add cart". pictures products given in folder pictures. informations products kept in class product. classes product , products should used ready-made classes. @ top of page button “buy” activates servlet buyservlet.mk. servlet need calculate total price user need pay products. naplata.html generate username , total price printed.
here html code
<form action="signinservlet.mk " method="post"> <label> user name <input type="text" name="name" > </label> <br /> <label> password <input type="password" name="pass"></label> <br />
and here servlet signinservlet.mk
protected void processrequest(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { response.setcontenttype("text/html;charset=utf-8"); printwriter out = response.getwriter(); try { cookie ime=new cookie("name",request.getparameter("name")); ime.setmaxage(60*60*24); response.addcookie(name); httpsession session=request.getsession(); products pr = new products(); out.println("<html>"); out.println("<head>"); out.println("<title>catalog</title>"); out.println("</head>"); out.println("<body>"); out.println("<input type='button' action='buyservlet.mk' value='buy products'"); out.println("<br />"); out.println("<br />"); out.println("<br />"); out.println("<br />"); for(int i=0; i<pr.getcatalog().size();i++) { out.println("<br />"); out.print("<p><img src='" + pr.getkatalog().get(i).getpicture()+ "'>"); out.print(pr.getkatalog().get(i).gettitle()); out.print(pr.getkatalog().get(i).getprice()); out.print("<input type='button' value='add card'"></p> "); } out.println("</body>"); out.println("</html>");
i wrote function don't know how add button.
public void add(httpsession session ,double price){ double sum=(double)session.getattribute("sum"); if(sum==null){ sum = new double(price); } else { sum = new double(sum.intvalue()+ price); } session.setattribute("sum", sum); }
Comments
Post a Comment