⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkout.java

📁 《J2EE企业级应用开发》一书的配套源代码
💻 JAVA
字号:
package com.j2eeapp.cdstore.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.j2eeapp.cdstore.bean.*;
import com.j2eeapp.cdstore.vo.*;

public class CheckOut extends HttpServlet
{
    private static final String CONTENT_TYPE = "text/html";
    /**
     * @J2EE_METHOD  --  doGet
     * Called by the server (via the service method) to allow a servlet to handle a GET request.
     * The servlet container must write the headers before committing the response, because
     * in HTTP the headers must be sent before the response body. The GET method should
     * be safe and idempotent. If the request is incorrectly formatted, doGet returns an
     * HTTP 'Bad Request' message.
     * @throws javax.servlet.ServletException
     * @throws java.io.IOException
     */
    public void doGet    (HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException 
    {
    	
        String orderId="";
        String cusername = request.getParameter("cusername");
        String cemail = request.getParameter("cemail");
        String cphone = request.getParameter("cphone");
        String cstreet = request.getParameter("cstreet");
        String ccity = request.getParameter("ccity");
        String cstate = request.getParameter("cstate");
        String czipCode = request.getParameter("czipCode");
        
        String busername = request.getParameter("busername");
        String bstreet = request.getParameter("bstreet");
        String bcity = request.getParameter("bcity");
        String bstate = request.getParameter("bstate");
        String bzipCode = request.getParameter("bzipCode");
        
        String susername = request.getParameter("susername");
        String sstreet = request.getParameter("sstreet");
        String scity = request.getParameter("scity");
        String sstate = request.getParameter("sstate");
        String szipCode = request.getParameter("szipCode");
        
        String cardNumber = request.getParameter("cardNumber");
        String cardType = request.getParameter("cardType");
        String cardPassword=request.getParameter("cardPassword");
        
        Address contactAddress=new Address(cstreet,ccity,cstate,czipCode);
        ContactInfo contactInfo=new ContactInfo(cusername,cphone,cemail,contactAddress);
        ShippingInfo shippingInfo=new ShippingInfo(susername,sstreet,scity,sstate,szipCode);
        BillingInfo billingInfo=new BillingInfo(busername,bstreet,bcity,bstate,bzipCode);
        CreditCard card=new CreditCard(cardNumber,cardType,new java.util.Date());
        ShoppingSession shoppingSession = (ShoppingSession) request.getSession().getAttribute("shoppingSession");
	    try {
	         orderId=shoppingSession.checkOut(contactInfo,shippingInfo,billingInfo,card,cardPassword);
	         System.out.println(orderId);
	    }
	    catch (Exception ex) {
	      ex.printStackTrace();
	    }
	    RequestDispatcher d = request.getRequestDispatcher("ordercompleted?orderId="+orderId);
	    d.forward(request, response);

    }
    
    
    /**
     * @J2EE_METHOD  --  doPost
     * Called by the server (via the service method) to allow a servlet to handle a POST
     * request. The HTTP POST method allows the client to send data of unlimited length
     * to the Web server a single time and is useful when posting information such as credit
     * card numbers. If the HTTP POST request is incorrectly formatted, doPost returns
     * an HTTP 'Bad Request' message.
     * @throws javax.servlet.ServletException
     * @throws java.io.IOException
     */
    public void doPost    (HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException 
    {
			doGet(request,response);
    }
    
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -