Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. |
| 3 | * |
| 4 | * This program and the accompanying materials are made available under the |
| 5 | * terms of the Eclipse Public License v. 2.0, which is available at |
| 6 | * http://www.eclipse.org/legal/epl-2.0. |
| 7 | * |
| 8 | * This Source Code may also be made available under the following Secondary |
| 9 | * Licenses when the conditions for such availability set forth in the |
| 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| 11 | * version 2 with the GNU Classpath Exception, which is available at |
| 12 | * https://www.gnu.org/software/classpath/license.html. |
| 13 | * |
| 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | */ |
| 16 | |
| 17 | package test; |
| 18 | |
| 19 | import java.io.*; |
| 20 | import java.net.*; |
| 21 | import java.util.*; |
| 22 | import javax.servlet.*; |
| 23 | import javax.servlet.http.*; |
| 24 | import org.xml.sax.InputSource; |
| 25 | import org.w3c.dom.Element; |
| 26 | import org.w3c.dom.Document; |
| 27 | import org.w3c.dom.NodeList; |
| 28 | import org.w3c.dom.Node; |
| 29 | |
| 30 | import org.xml.sax.SAXException; |
| 31 | import org.xml.sax.SAXParseException; |
| 32 | import org.xml.sax.SAXException; |
| 33 | |
| 34 | // jaxp 1.0.1 imports |
| 35 | import javax.xml.parsers.DocumentBuilderFactory; |
| 36 | import javax.xml.parsers.DocumentBuilder; |
| 37 | |
| 38 | import java.net.URL; |
| 39 | import java.util.ArrayList; |
| 40 | import java.util.HashMap; |
| 41 | |
| 42 | import javax.naming.*; |
| 43 | import javax.sql.*; |
| 44 | import java.sql.*; |
| 45 | |
| 46 | public class ServletTest extends HttpServlet implements HttpSessionListener { |
| 47 | |
| 48 | private ServletContext context; |
| 49 | |
| 50 | public void init(ServletConfig config) throws ServletException { |
| 51 | super.init(config); |
| 52 | System.out.println("[Servlet.init]"); |
| 53 | context = config.getServletContext(); |
| 54 | System.out.println("[Servlet.init] " + context.getMajorVersion()); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
| 59 | System.out.println("[Servlet.doGet]"); |
| 60 | doPost(request, response); |
| 61 | } |
| 62 | |
| 63 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
| 64 | System.out.println("[Servlet.doPost]"); |
| 65 | |
| 66 | response.setContentType("text/html"); |
| 67 | PrintWriter out = response.getWriter(); |
| 68 | |
| 69 | request.getSession().setAttribute("FILTER-REQUEST", request.getSession().getAttribute("FILTER")); |
| 70 | request.getSession().setAttribute("FILTER", "FAIL"); |
| 71 | |
| 72 | RequestDispatcher rd = context.getRequestDispatcher("/ServletTest2"); |
| 73 | rd.forward(request, response); |
| 74 | } |
| 75 | |
| 76 | public void sessionCreated(javax.servlet.http.HttpSessionEvent httpSessionEvent) { |
| 77 | System.out.println("[Servlet.sessionCreated]"); |
| 78 | } |
| 79 | |
| 80 | public void sessionDestroyed(javax.servlet.http.HttpSessionEvent httpSessionEvent) { |
| 81 | System.out.println("[Servlet.sessionDestroyed]"); |
| 82 | System.out.println("Attributes: " + httpSessionEvent.getSession().getAttribute("test")); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |