• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Libphonenumber Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * @author Shaopeng Jia
17  */
18 
19 package com.google.phonenumbers.demo;
20 
21 import static java.nio.charset.StandardCharsets.UTF_8;
22 
23 import com.google.phonenumbers.demo.render.InputFormRenderer;
24 import java.io.IOException;
25 import javax.servlet.http.HttpServlet;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 
29 /**
30  * A servlet that accepts requests that contain strings representing a phone number and a default
31  * country, and responds with results from parsing, validating and formatting the number. The
32  * default country is a two-letter region code representing the country that we are expecting the
33  * number to be from.
34  */
35 @SuppressWarnings("serial")
36 public class InputServlet extends HttpServlet {
37 
38   /** Handle the get request to get information about a number based on query parameters. */
doGet(HttpServletRequest req, HttpServletResponse resp)39   public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
40     resp.setContentType("text/html");
41     resp.setCharacterEncoding(UTF_8.name());
42     resp.getWriter().println(new InputFormRenderer().genHtml());
43   }
44 }
45