Package com.sun.bookstore1.servlets

Examples of com.sun.bookstore1.servlets.ShowCartServlet


        context.setAttribute("hitCounter", counter);
        counter = new Counter();
        context.setAttribute("orderCounter", counter);

        try {
            BookDBAO bookDB = new BookDBAO(emf);
            context.setAttribute("bookDB", bookDB);
        } catch (Exception ex) {
            System.out.println(
                    "Couldn't create bookstore database bean: "
                    + ex.getMessage());
View Full Code Here


    public void contextDestroyed(ServletContextEvent event) {
        context = event.getServletContext();
        context.removeAttribute("hitCounter");
        context.removeAttribute("orderCounter");

        BookDBAO bookDB = (BookDBAO) context.getAttribute("bookDB");

        if (bookDB != null) {
            bookDB.remove();
        }

        context.removeAttribute("bookDB");
    }
View Full Code Here

        // Log the resulting string
        writer.flush();
        System.out.println(sw.getBuffer().toString());

        PrintWriter out = response.getWriter();
        CharResponseWrapper wrapper = new CharResponseWrapper(
                    (HttpServletResponse) response);
        chain.doFilter(request, wrapper);

        CharArrayWriter caw = new CharArrayWriter();
        caw.write(
                wrapper.toString().substring(
                        0,
                        wrapper.toString().indexOf("</body>") - 1));
        caw.write(
                "<p>\n<center>" + messages.getString("Visitor")
                + "<font color='red'>" + counter.getCounter()
                + "</font></center>");
        caw.write("\n</body></html>");
View Full Code Here

        }

        StringWriter sw = new StringWriter();
        PrintWriter writer = new PrintWriter(sw);

        Counter counter = (Counter) filterConfig.getServletContext()
                                                .getAttribute("hitCounter");
        writer.println();
        writer.println(
                "=======================================================");
        writer.println("The number of hits is: " + counter.incCounter());
        writer.println(
                "=======================================================");

        // Log the resulting string
        writer.flush();
        System.out.println(sw.getBuffer().toString());

        PrintWriter out = response.getWriter();
        CharResponseWrapper wrapper = new CharResponseWrapper(
                    (HttpServletResponse) response);
        chain.doFilter(request, wrapper);

        CharArrayWriter caw = new CharArrayWriter();
        caw.write(
                wrapper.toString().substring(
                        0,
                        wrapper.toString().indexOf("</body>") - 1));
        caw.write(
                "<p>\n<center>" + messages.getString("Visitor")
                + "<font color='red'>" + counter.getCounter()
                + "</font></center>");
        caw.write("\n</body></html>");
        response.setContentLength(caw.toString()
                                     .getBytes().length);
        out.write(caw.toString());
View Full Code Here

    private ServletContext context = null;

    public void contextInitialized(ServletContextEvent event) {
        context = event.getServletContext();

        Counter counter = new Counter();
        context.setAttribute("hitCounter", counter);
        counter = new Counter();
        context.setAttribute("orderCounter", counter);

        try {
            BookDBAO bookDB = new BookDBAO(emf);
            context.setAttribute("bookDB", bookDB);
View Full Code Here

        if (bookId != null) {
            // and the information about the book
            try {
                Book bd = bookDB.getBook(bookId);
                Currency c = (Currency) session.getAttribute("currency");

                if (c == null) {
                    c = new Currency();
                    c.setLocale(request.getLocale());
                    session.setAttribute("currency", c);
                }

                c.setAmount(bd.getPrice());

                //Print out the information obtained
                out.println(
                        "<h2>" + bd.getTitle() + "</h2>" + "&nbsp;"
                        + messages.getString("By") + " <em>"
                        + bd.getFirstName() + " " + bd.getSurname()
                        + "</em> &nbsp; &nbsp; " + "(" + bd.getCalendar_year()
                        + ")<br> &nbsp; <br>" + "<h4>"
                        + messages.getString("Critics") + "</h4>"
                        + "<blockquote>" + bd.getDescription()
                        + "</blockquote>" + "<h4>"
                        + messages.getString("Price") + c.getFormat() + "</h4>"
                        + "<p><strong><a href=\""
                        + response.encodeURL(
                                request.getContextPath()
                                + "/bookcatalog?bookId=" + bookId) + "\">"
                        + messages.getString("CartAdd")
View Full Code Here

                    + "</TH>" + "<th align=left>"
                    + messages.getString("ItemPrice") + "</TH>" + "</tr>");

            Iterator i = cart.getItems()
                             .iterator();
            Currency c = (Currency) session.getAttribute("currency");

            if (c == null) {
                c = new Currency();
                c.setLocale(request.getLocale());
                session.setAttribute("currency", c);
            }

            while (i.hasNext()) {
                ShoppingCartItem item = (ShoppingCartItem) i.next();
                bd = (Book) item.getItem();
                c.setAmount(bd.getPrice());

                out.println(
                        "<tr>" + "<td align=\"right\" bgcolor=\"#ffffff\">"
                        + item.getQuantity() + "</td>"
                        + "<td bgcolor=\"#ffffaa\">" + "<strong><a href=\""
                        + response.encodeURL(
                                request.getContextPath()
                                + "/bookdetails?bookId=" + bd.getBookId())
                        + "\">" + bd.getTitle() + "</a></strong>" + "</td>"
                        + "<td bgcolor=\"#ffffaa\" align=\"right\">"
                        + c.getFormat() + "</td>" + "<td bgcolor=\"#ffffaa\">"
                        + "<strong>" + "<a href=\""
                        + response.encodeURL(
                                request.getContextPath()
                                + "/bookshowcart?Remove=" + bd.getBookId())
                        + "\">" + messages.getString("RemoveItem")
                        + "</a></strong>" + "</td></tr>");
            }

            c.setAmount(cart.getTotal());
            // Print the total at the bottom of the table
            out.println(
                    "<tr><td colspan=\"5\" bgcolor=\"#ffffff\">"
                    + "<br></td></tr>" + "<tr>"
                    + "<td colspan=\"2\" align=\"right\""
                    + "bgcolor=\"#ffffff\">" + messages.getString("Subtotal")
                    + "</td>" + "<td bgcolor=\"#ffffaa\" align=\"right\">"
                    + c.getFormat() + "</td>"
                    + "</td><td><br></td></tr></table>");

            // Where to go and what to do next
            out.println(
                    "<p> &nbsp; <p><strong><a href=\""
View Full Code Here

        try {
            Collection coll = bookDB.getBooks();

            Iterator i = coll.iterator();
            Currency c = (Currency) session.getAttribute("currency");

            if (c == null) {
                c = new Currency();
                c.setLocale(request.getLocale());
                session.setAttribute("currency", c);
            }

            while (i.hasNext()) {
                Book book = (Book) i.next();
                bookId = book.getBookId();
                c.setAmount(book.getPrice());

                //Print out info on each book in its own two rows
                out.println(
                        "<tr>" + "<td bgcolor=\"#ffffaa\">" + "<a href=\""
                        + response.encodeURL(
                                request.getContextPath()
                                + "/bookdetails?bookId=" + bookId)
                        + "\"> <strong>" + book.getTitle()
                        + "&nbsp; </strong></a></td>"
                        + "<td bgcolor=\"#ffffaa\" rowspan=2>" + c.getFormat()
                        + "&nbsp; </td>" + "<td bgcolor=\"#ffffaa\" rowspan=2>"
                        + "<a href=\""
                        + response.encodeURL(
                                request.getContextPath()
                                + "/bookcatalog?bookId=" + bookId)
View Full Code Here

        // set content-type header before accessing Writer
        response.setContentType("text/html");

        PrintWriter out = response.getWriter();
        Currency c = (Currency) session.getAttribute("currency");

        if (c == null) {
            c = new Currency();
            c.setLocale(request.getLocale());
            session.setAttribute("currency", c);
        }

        c.setAmount(cart.getTotal());

        // then write the data of the response
        out.println(
                "<html>" + "<head><title>" + messages.getString("TitleCashier")
                + "</title></head>");

        // Get the dispatcher; it gets the banner to the user
        RequestDispatcher dispatcher = getServletContext()
                                           .getRequestDispatcher("/banner");

        if (dispatcher != null) {
            dispatcher.include(request, response);
        }

        // Print out the total and the form for the user
        out.println(
                "<p>" + messages.getString("Amount") + "<strong>"
                + c.getFormat() + "</strong>" + "<p>"
                + messages.getString("Purchase") + "<form action=\""
                + response.encodeURL(request.getContextPath() + "/bookreceipt")
                + "\" method=\"post\">" + "<table summary=\"layout\">" + "<tr>"
                + "<td><strong>" + messages.getString("Name")
                + "</strong></td>"
View Full Code Here

TOP

Related Classes of com.sun.bookstore1.servlets.ShowCartServlet

Copyright © 2018 www.massapicom. 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.