Package com.lgx8.gateway.servlet

Source Code of com.lgx8.gateway.servlet.GatewayNavServlet

package com.lgx8.gateway.servlet;

import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.lgx8.common.util.Constants;
import com.lgx8.gateway.entities.Orders;
import com.lgx8.gateway.service.IOrderService;
import com.lgx8.right.entities.RunTimeUser;

import freemarker.template.Template;
import freemarker.template.TemplateException;

/**
* Servlet implementation class GatewayNavServlet
*/
public class GatewayNavServlet extends GatewayBaseServlet {
  private static final long serialVersionUID = 1L;
      
    /**
     * @see GatewayBaseServlet#GatewayBaseServlet()
     */
    public GatewayNavServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
  }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Template temp = getConfiguration().getTemplate("nav.ftl");
   
    Map<Object, Object> root = new HashMap<Object, Object>();
    root.putAll(super.root);
   
    String aid = request.getParameter("aid");
    long areaCategoryId = 0;
    try {
      areaCategoryId = Long.parseLong(aid);
    } catch (Exception e2) {
      areaCategoryId = 0;
    }
    root.put("areaCategoryId", areaCategoryId);
   
    RunTimeUser user = null;
    try {
      user = RunTimeUser.getRunTimeUser(request);
    } catch (Exception e1) {
      user = null;
    }
   
    ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IOrderService ordersService = (IOrderService) ac.getBean("orderService");
   
   
    if(user!=null) {
      root.put("user", user);
      Orders order = ordersService.findCartByUserId(user.getId());
      if(order!=null) {
        root.put("order", order);
      }
      root.put("delete_cart_product_url", Constants.DELETE_CART_PRODUCT_URL);
      root.put("show_cart_url", Constants.SHOW_CART_URL);
    }
   
    /* 将模板和数据模型合并 */
    Writer out = response.getWriter();
    try {
      temp.process(root, out);
    } catch (TemplateException e) {
      e.printStackTrace();
    }
    out.flush();
  }

}
TOP

Related Classes of com.lgx8.gateway.servlet.GatewayNavServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.