Sparkでフォームデータを取り出す
フォームデータの送信はGETを使う場合とPOSTを使う場合があります。
Spark micro framewotk(Spark java)はどちらで送られてきたかを区別しないで、Request#queryParams(String)で取り出せます。
Spark micro framewotk(Spark java)はどちらで送られてきたかを区別しないで、Request#queryParams(String)で取り出せます。
GET
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
<form action="http://localhost:8080/test/postget" method="get"> | |
<input type="hidden" name="msg" value="method is get"/> | |
<button type="submit">GET</button> | |
</form> |
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
get( "/test/postget", (req, res) ->{ | |
String p = req.queryParams("msg"); | |
return "queryParams(msg)="+p; | |
}); |
POST
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
<form action="http://localhost:8080/test/postget" method="post"> | |
<input type="hidden" name="msg" value="method is post"/> | |
<button type="submit">POST</button> | |
</form> |
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
post( "/test/postget", (req, res) ->{ | |
String p = req.queryParams("msg"); | |
return "queryParams(msg)="+p; | |
}); |