我正在尝试在发布请求中从我的html页面获取表单数据,但是当我使用getFormAttribute()函数时,它返回null。这是代码:
Route postArticleRoute = router
.post("/articlePosted")
.handler(routingContext -> {
HttpServerResponse response = routingContext.response();
HttpServerRequest request = routingContext.request();
String title = request.getFormAttribute("title");
String auth = request.getFormAttribute("author");
String body = request.getFormAttribute("body");
System.out.println(title + auth + body);
});
此代码返回:'nullnullnull'
我已经仔细检查了这些是html表单中的名称属性。以防万一,这是html:
<form action="/articlePosted" method="post">
<label>Title of Article</label><br>
<input type="text" name="title" id="postArticle-title"><br><br>
<label>Author</label><br>
<input type="text" name="author" id="postArticle-auth"><br><br>
<label>Image</label><br>
<input type="file" name="file" id="postArticle-img"><br><br>
<label>Body</label><br>
<textarea style="width: 100%; height: 500px;" name="body" id="postArticle-body"></textarea><br><br>
<input type="submit" value="Post">
</form>
任何帮助将不胜感激。