receiptservlet.java

来自「J2EE导学」· Java 代码 · 共 64 行

JAVA
64
字号
/* * * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. *  * This software is the proprietary information of Sun Microsystems, Inc.   * Use is subject to license terms. *  */import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import cart.ShoppingCart;/** * An HTTP servlet that responds to the POST method of the HTTP protocol. * It clears the shopping cart, thanks the user for the order, * and resets the page to the Bookstore's main page. */public class ReceiptServlet extends HttpServlet {     public void doPost(HttpServletRequest request,                       HttpServletResponse response) throws ServletException, IOException    {        // Get the user's session and shopping cart        HttpSession session = request.getSession(true);        // Payment received -- invalidate the session        session.invalidate();                // set content type header before accessing the Writer        response.setContentType("text/html");            response.setBufferSize(8192);            PrintWriter out = response.getWriter();                // then write the response        out.println("<html>" +                    "<head><title> Receipt </title>" + "</head>" );        // Get the dispatcher; it gets the banner to the user        RequestDispatcher dispatcher =               getServletContext().getRequestDispatcher("/banner");                                                   if (dispatcher != null)               dispatcher.include(request, response);                             out.println("<h3>Thank you for purchasing your books from us " +         request.getParameter("cardname") + ".");      out.println("<p> &nbsp; <p><strong><a href=\"" +         response.encodeURL("/bookstore1/catalog") +         "\">Continue Shopping?</a> &nbsp; &nbsp; &nbsp;" +         "</body></html>");        out.close();    }    public String getServletInfo() {        return "The Receipt servlet clears the shopping cart, " +               "thanks the user for the order, and resets the " +               "page to the BookStore's main page.";    }}

⌨️ 快捷键说明

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