Mercurial > hg > Members > nobuyasu > tasks
changeset 14:ce84c877fee6 draft default tip
modify controllers.Sample class
author | one |
---|---|
date | Tue, 18 Sep 2012 04:28:13 +0900 |
parents | 3e2b8b01e3b6 |
children | |
files | app/controllers/Sample.java |
diffstat | 1 files changed, 20 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controllers/Sample.java Tue Sep 18 02:30:36 2012 +0900 +++ b/app/controllers/Sample.java Tue Sep 18 04:28:13 2012 +0900 @@ -1,5 +1,11 @@ package controllers; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.List; import javax.ws.rs.core.Request; @@ -8,12 +14,23 @@ import models.Post; import play.mvc.Controller; +import play.mvc.Http; public class Sample extends Controller { - public static void index() { - String id = params.get("id"); - String str = "{ \"id\" : \""+id +"\"}"; + public static void index() throws IOException { + String method = request.method; + String str=""; + if (method.equals("POST")) { + InputStream in = request.body; + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String tmp =""; + while ( (tmp = br.readLine()) != null) str += tmp; + + } else { + String id = params.get("id"); + str = "{ \"id\" : \""+id +"\"}"; + } renderJSON(str); }