blob: 9fe46d3561c8cb7df54b0fbc9d5ef5d94eb4f9ec [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
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
17package test;
18
19import java.io.*;
20import java.net.*;
21import java.util.*;
22import javax.servlet.*;
23import javax.servlet.http.*;
24import org.xml.sax.InputSource;
25import org.w3c.dom.Element;
26import org.w3c.dom.Document;
27import org.w3c.dom.NodeList;
28import org.w3c.dom.Node;
29
30import org.xml.sax.SAXException;
31import org.xml.sax.SAXParseException;
32import org.xml.sax.SAXException;
33
34// jaxp 1.0.1 imports
35import javax.xml.parsers.DocumentBuilderFactory;
36import javax.xml.parsers.DocumentBuilder;
37
38import java.net.URL;
39import java.util.ArrayList;
40import java.util.HashMap;
41
42import javax.naming.*;
43import javax.sql.*;
44import java.sql.*;
45
46public 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