このエラーの解決方法はいくつか見てきましたが、どれも解決していません。私はこのHTMLを持っています:Spring MVCのPOSTメソッド:Tomcatで「要求されたリソースが利用できません」
<section ng-app="myApp" ng-controller="button">
<article id = "id-input">
<form id = "id-form" method = "post" >
VOC ID:<input name = "guid" type = "text" ng-model = "input" required>
<button name = "button" value = "button" ng-click = "pressed()" type = "submit">Generate ></button>
</form>
</article>
</section>
ユーザーが "ボタン"をクリックしたときにPOSTメソッドを使用してフォームを送信しようとしています。それから、これはJS実行:
app.controller('button', function($scope, $http) {
$scope.show = false;
$scope.pressed = function() {
$http({
method : "POST",
url : "/test"
}).then(function mySuccess(response) {
document.getElementById("id-input").style.paddingBottom = "5px";
$scope.show = true;
$scope.finalinput = $scope.input;
}, function myError(response) {
document.body.innerHTML = response.data;
});
};
});
成功し、私は要求に対処するための春構成されたクラスを持つPOSTリクエストを送信した後:
@Controller
public class MainTest{
@Inject @Singleton
private VocDBService s;
@RequestMapping(value = "/test", method = RequestMethod.POST)
public void doPost(final HttpServletRequest httpServletRequest) {
String guid = httpServletRequest.getParameter("guid");
List<UserInfo> dataex = s.getData(guid);
System.out.println(dataex.get(0));
}
}
問題は、私が手ボタンをクリックした後、ありますメッセージ:/ testと "要求されたリソースは利用できません"。 POST要求が送信されたときにコントローラが認識されないのはなぜですか?私はTomcat v7サーバーで動作しています。
あなたの問題を解決するAjaxコールにコンテンツタイプを追加してください –