Created
March 1, 2014 23:16
-
-
Save msdalp/9299098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.msd.jetty; | |
import com.google.gson.Gson; | |
import com.google.gson.JsonObject; | |
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
@SuppressWarnings("serial") | |
public class GetName extends HttpServlet { | |
private final Gson gson; | |
public GetTeamDictionary(Gson gson) { | |
this.gson = gson; | |
} | |
@Override | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
String output = ""; | |
try { | |
final JsonObject retVal = new JsonObject(); | |
retVal.add("name", "jetty"); | |
retVal.add("surname", "is awasome"); | |
output = retVal.toString(); | |
response.setStatus(HttpServletResponse.SC_OK); | |
} catch (Exception ex) { | |
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | |
} finally { | |
response.setContentType("text/html;charset=UTF-8"); | |
response.getWriter().println(output); | |
response.getWriter().close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment