![](/img/trans.png)
[英]HTTP Status 400 The request sent by the client was syntactically incorrect in Spring
[英]HTTP Status 400 - The request sent by the client was syntactically incorrect with spring
當我嘗試提交“添加表單”時,我的HTTP狀態為400,我也搜索了此問題,並且大多數解決方案都與controller和@RequestParameter一起考慮。
形式如下:
<form:form commandName="blog" id="newBlog" method="POST"
cssClass="form-horizontal" action="account">
<table class="k-widge">
<tr>
<th>Name:</th>
<td><form:input path="name" cssClass="k-textbox"
style="margin-top:3px; margin-bottom: 5px;" name="name"/></td>
</tr>
<tr>
<th>Url:</th>
<td><form:input path="url" cssClass="k-textbox"
style="margin-bottom: 5px;" name="url"/></td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="Save" Class="k-button" id="saveBlog"
style="margin-bottom: 5px;"/></td>
</tr>
</table>
</form:form>
和控制器:
@RequestMapping(value="/account",method=RequestMethod.POST)
public String doAddBlog(@ModelAttribute("blog") Blog blog,Principal principal){
String name = principal.getName();
blogService.save(blog,name);
return "redirect:/account.html";
}
終於,我解決了這個問題。 問題是,當我提交表單時,該表單中以“帳戶”形式存在的動作會附加到當前URL:
當前網址“ localhost:8080 / myapp / users”
當我提交表格時,它會像這樣
“本地主機:8080 / MyApp的/用戶/帳戶”
並且該“ / users / account”在控制器類的請求映射中不存在。
因此,我要做的是在表單操作中添加“ / myapp / account”而不是“ account”。
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.