public class TotalSalesGraphicServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("查看hichart表....");
request.setCharacterEncoding("utf-8");
User existUser = (User)request.getSession().getAttribute("existUser");
if(existUser==null){
response.sendRedirect(request.getContextPath()+"/login.jsp");
return;
}
List<Product> products = new OrderItemServiceImpl().findTotalSales();
//将products抽取出来 封装特殊格式字符串
List<SalesData> saleDatas = new ArrayList<SalesData>();
for(Product p:products){
SalesData salesData = new SalesData();
salesData.setName(p.getName());
int arr[] = new int[1];
arr[0] = p.getTotalSales();
salesData.setData(arr);
saleDatas.add(salesData);
}
JSONArray array = JSONArray.fromObject(saleDatas);
response.setContentType("text/json;charset=utf-8");
response.getWriter().println(array.toString());
}
}
|
|