View Javadoc
1   /*
2    * Copyright (C) 2007-2014 JMPEAX.
3    *
4    *     This program is free software: you can redistribute it and/or modify
5    *     it under the terms of the GNU General Public License as published by
6    *     the Free Software Foundation, either version 3 of the License, or
7    *     (at your option) any later version.
8    *
9    *     This program is distributed in the hope that it will be useful,
10   *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *     GNU General Public License for more details.
13   *
14   *     You should have received a copy of the GNU General Public License
15   *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  
18  package com.jmpeax.osgi.undertow.http;
19  
20  import javax.servlet.ServletException;
21  import javax.servlet.http.HttpServlet;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  import java.io.IOException;
25  
26  /**
27   *
28   */
29  public class SampleServlet extends HttpServlet {
30  
31  
32      public static final java.lang.String SEND_TEXT = "Hello from Servlet";
33      public static final String ENCODING = "utf-8";
34      public static final String CONTENT_TYPE = "text/plain;charset=" + ENCODING;
35  
36      public SampleServlet() {
37      }
38  
39      @Override
40      protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
41          resp.setStatus(HttpServletResponse.SC_OK);
42          resp.setHeader("Accept-Charset", ENCODING);
43          resp.setContentType(CONTENT_TYPE);
44          resp.getWriter().write(SEND_TEXT);
45      }
46  }