View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.servlet.filterlistener;
18  
19  import java.io.IOException;
20  import java.io.PrintWriter;
21  
22  import javax.servlet.ServletException;
23  import javax.servlet.annotation.WebServlet;
24  import javax.servlet.http.HttpServlet;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  
28  /**
29   * A simple servlet that exists as a target for Servlet Filters and Servlet Listeners.
30   * 
31   * @author Jonathan Fuerth <jfuerth@redhat.com>
32   */
33  @SuppressWarnings("serial")
34  @WebServlet("/FilterExample")
35  public class FilterExampleServlet extends HttpServlet {
36  
37      @Override
38      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
39          PrintWriter writer = resp.getWriter();
40          writer.println("<!DOCTYPE HTML>");
41          writer.println("<html>");
42          writer.println(" <head>");
43          writer.println("  <title>servlet-filterlistener</title>");
44          writer.println(" </head>");
45          writer.println(" <body>");
46          writer.println("  <form>");
47          writer.println("   <label for=userInput>Enter some text:</label> <input type=text name=userInput>");
48          writer.println("   <button type=submit>Send</button></form>");
49          writer.println("  </form>");
50  
51          if (req.getParameter("userInput") != null) {
52              writer.println("  <h1>You Typed: " + req.getParameter("userInput") + "</h1>");
53          }
54  
55          writer.println(" </body>");
56          writer.println("</html>");
57          writer.close();
58      }
59  
60  }