Last active
December 16, 2015 03:30
-
-
Save rkaneko/5370690 to your computer and use it in GitHub Desktop.
Handling POST request on Play! framework(v2.1.0) .
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
import java.util.Iterator; | |
import java.util.Map; | |
import java.util.Set; | |
import play.Logger; | |
import play.mvc.Controller; | |
import play.mvc.Result; | |
import play.data.DynamicForm; | |
import static play.data.Form.form; | |
public class Application extends Controller { | |
public static Result post() { | |
Map<String, String[]> form = request().body().asFormUrlEncoded(); | |
if (form == null) { | |
Logger.info("params is null"); | |
return badRequest("params is null"); | |
} else { | |
Set<String> keySet = form.keySet(); | |
Iterator<String> iterator = keySet.iterator(); | |
while (iterator.hasNext()) { | |
final String KEY = iterator.next(); | |
Logger.info("key is : " + KEY); | |
final String[] VALUES = form.get(KEY); | |
for (String value : VALUES) { | |
Logger.info(value); | |
} | |
} | |
return ok(); | |
} | |
} | |
public static Result post2() { | |
DynamicForm form = form().bindFromRequest(); | |
String value = form.get("key"); | |
Logger.info("key is : " + value); | |
return ok() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment