|
| 1 | +/** |
| 2 | + * Copyright 2017 Google Inc. |
| 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 | + |
| 17 | + |
| 18 | +package com.example.appengine.clouddebugger; |
| 19 | + |
| 20 | +import javax.servlet.annotation.WebServlet; |
| 21 | +import javax.servlet.http.HttpServlet; |
| 22 | +import javax.servlet.http.HttpServletRequest; |
| 23 | +import javax.servlet.http.HttpServletResponse; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | +import java.io.PrintWriter; |
| 27 | + |
| 28 | +@WebServlet(value = "/") |
| 29 | +public class DebugServlet extends HttpServlet { |
| 30 | + |
| 31 | + @Override |
| 32 | + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| 33 | + |
| 34 | + String userAgent = request.getHeader("User-Agent"); |
| 35 | + String displayName = "Browser"; |
| 36 | + |
| 37 | + if (userAgent != null) { |
| 38 | + if (userAgent.contains("Mozilla")) { |
| 39 | + displayName = "Firefox"; |
| 40 | + } else if (userAgent.contains("Explorer")) { |
| 41 | + displayName = "Internet Explorer"; |
| 42 | + } else if (userAgent.contains("Safari")) { |
| 43 | + displayName = "Safari"; |
| 44 | + } else if (userAgent.contains("Chrome")) { |
| 45 | + displayName = "Chrome"; |
| 46 | + } else if (userAgent.contains("Opera")) { |
| 47 | + displayName = "Opera"; |
| 48 | + } else { |
| 49 | + displayName = userAgent; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + response.setContentType("text/html"); |
| 54 | + PrintWriter writer = response.getWriter(); |
| 55 | + |
| 56 | + writer.println("<html><body><h1>"); |
| 57 | + writer.println("Hello " + displayName); |
| 58 | + writer.println("</h1></body></html>"); |
| 59 | + } |
| 60 | +} |
0 commit comments