0
我正在嘗試使用Spring Boot並希望爲Spring Controller執行一個Ajax POST。我從POSTMAN測試它,但後來我一直得到這個錯誤。Jquery Ajax發佈Spring MVC控制器?
{
"timestamp": 1499255141424,
"status": 404,
"error": "Not Found",
"message": "/WEB-INF/view/jsondata.jsp",
"path": "/jsondata"
}
我希望它在我的索引控制器中尋找jsondata方法。但它在我的觀點中尋找jsondata.jsp。
@RequestMapping(value = "/jsondata", method = RequestMethod.POST)
public void getfeeddata(@RequestBody String info)
{
System.out.println(info);
}
視圖 -
<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html lang="en">
<body>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function()
{
var info =[];
info.push("JsonPostdata");
$.ajax({
type: "post",
url: "/jsondata",
data: JSON.stringify(info),
success: function(msg){
console.log("success");
}
});
});
});
</script>
</head>
<div>
<div>
<h1>Spring Boot JSP Example</h1>
<form >
<input type="submit" id ="submit" value="Not clicked">
</form>
<h2>Hello ${message}</h2>
Click on this <strong><a href="next">link</a></strong> to visit another page.
</div>
</div>
</body>
</html>
你能分享屬性文件中呢? –
測試網址。我認爲問題是頁面沒有定義。乾淨的代碼並重新編譯。 –
你可以顯示你的完整控制器類嗎? – Plog