2014-09-10 67 views
0

新玩PlayFramwork和遇到障礙。 @https://www.playframework.com/documentation/2.3.x/JavaForms上的教程通過將表單輸入綁定到類來顯示處理表單。但是,我想處理HTML表單而不將我的字段綁定到類。我的形式Play Framework:處理POST params?

例子:

<form method="POST" action="form/submit"> 
<input type="file" name="slider[1][file]" class="thumbnailUpload"> 
<input type="text" value="http://www.tapiture.com/shop/collection1" name="slider[1][url]" class="form-control"> 
<input type="file" name="slider[2][file]" class="thumbnailUpload"> 
<input type="text" value="http://www.tapiture.com/shop/collection1" name="slider[3][url]" class="form-control"> 
<input type="file" name="slider[2][file]" class="thumbnailUpload"> 
<input type="text" value="http://www.tapiture.com/shop/collection1" name="slider[3][url]" class="form-control"> 
</form> 

我希望能夠在我的行動來處理這個像這樣:

String url = form.get("slider")[0]["url"] 

我已經試過

RequestBody body = request().body(); 
    final Map<String, String[]> values = body.asFormUrlEncoded(); 

而且做這個,我只能訪問像這樣的值

value.get("slider[1][url]") 

,但我得到

[Ljava.lang.String;@4d36e231 

HELP !!!!!!

回答

1

變量包含一個映射,其中值是一個字符串數組。所以用得到方法返回一個數組。要訪問參數的值,請查看它的第一個元素。

String value = values.get("slider[1][url]")[0]; 

我也注意到你要上傳文件。不要忘了,改變形式的是enctype後:

<form method="POST" action="form/submit" enctype="multipart/form-data"> 

訪問POST數據有:

final Map<String, String[]> values = body.asMultipartFormData().asFormUrlEncoded();