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

📄 showitems.java

📁 Online flight booking
💻 JAVA
字号:
package coreservlets;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.util.*;/** Servlet that displays a list of items being ordered. *  Accumulates them in an ArrayList with no attempt at *  detecting repeated items. Used to demonstrate basic *  session tracking. Updated to Java 5. *  <p> *  From <a href="http://courses.coreservlets.com/Course-Materials/">the *  coreservlets.com tutorials on servlets, JSP, Struts, JSF, Ajax, GWT, and Java</a>. */@SuppressWarnings("unchecked")public class ShowItems extends HttpServlet {    public void doGet(HttpServletRequest request,            HttpServletResponse response)            throws ServletException, IOException    {        HttpSession session = request.getSession();        if (session.getAttribute("login") == null) {            response.setContentType("text/html");            PrintWriter out = response.getWriter();            out.println("<html>");            out.println("<head>");            out.println("<title>User is not logged in</title>");            out.println("</head>");            out.println("<body>");            out.println("<br><p align=\"center\">Please log in <a href=\"./login.html\">here</a> first</p>");            out.println("</body>");            out.println("</html>");            out.close();            return;        }        List<String> previousItems =                (List<String>) session.getAttribute("previousItems");        if (previousItems == null) {            previousItems = new ArrayList<String>();            session.setAttribute("previousItems", previousItems);        }        String newItem = request.getParameter("newItem");        if ((newItem != null) &&                (!newItem.trim().equals(""))) {            previousItems.add(newItem);        }        response.setContentType("text/html");        PrintWriter out = response.getWriter();        String title = "Items Purchased";        String docType =                "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +                "Transitional//EN\">\n";        out.println(docType +                "<HTML>\n" +                "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +                "<BODY BGCOLOR=\"#FDF5E6\">\n" +                "<H1>" + title + "</H1>");        if (previousItems.size() == 0) {            out.println("<I>No items</I>");        } else {            out.println("<UL>");            for (String item : previousItems) {                out.println("  <LI>" + item);            }            out.println("</UL>");        }        out.println("</BODY></HTML>");    }}

⌨️ 快捷键说明

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