【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-AddCustomerServlet.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
package com.abc.store.hi;
import com.abc.store.pd.*;
import com.abc.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class AddCustomerServlet extends HttpServlet
{
HtmlTemplate addHTML;
Hashtable data;
public synchronized void init(ServletConfig servletconfig)
throws ServletException
{
super.init(servletconfig);
ServletContext servletcontext = getServletContext();
data = new Hashtable();
try
{
String path = getInitParameter("add");
addHTML = new HtmlTemplate(servletcontext.getRealPath(path));
}
catch(Exception ex)
{
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession(false);
Customer customer = (Customer)session.getValue("customer");
ShoppingCart cart = customer.getShoppingCart();
String htmlStr = "";
float total = 0;
Vector allItems = cart.getItems();
Enumeration enum = allItems.elements();
while (enum.hasMoreElements())
{
Item item = (Item)enum.nextElement();
int id = item.getId();
String name = item.getName();
float price = item.getPrice();
total += price;
htmlStr += "<tr><td>"+id+"</td><td>"+name+"</td><td align=right>"
+price+"</td></tr>";
}
data.put("total", ""+total);
data.put("items", htmlStr);
ServletOutputStream out = response.getOutputStream();
addHTML.print(out, data);
}
}
上一篇:
AddCourseInfo.java
下一篇:
月入5000,你有什么资格谈生活