JSP内でajaxポストを使用して、jsonデータをサーブレットJavaクラスに送信しています。サーブレット コントローラ クラス内で getparameter を使用して、呼び出し元の JSP から送信されるデータを取得しました。
この時点まで、これはすべて正常に機能します。次に、このサーブレット クラスからのデータの処理を開始し、呼び出し元の JSP に送り返すデータ応答を作成する必要があります。
servelt クラス内の変数にデータを保持し、(AJAX 投稿内の) 成功関数の一部としてこのデータにアクセスする方法はありますか?
私のAJAXポストコード:
$.ajax({
type: "POST",
url: url,
dataType: "text", // [text, xml, json, script, text, html]
data: {postData : myData, sendURL : postUrl},
success: function(data, textStatus, jqXHR) {
alert('Success post to URL entered \n\n The data returned the following: ' + data);
},
error:function (xhr, ajaxOptions, thrownError){
alert('Error xhr : ' + xhr.status);
alert('Error thrown error: ' + thrownError);
}
//complete: alert('complete')
});
私のサーブレットコントローラーコード:
@RequestMapping("/postData")
public String postData(Model model, HttpServletRequest request) throws Throwable{
String postData = request.getParameter("postData");
String sendURL= request.getParameter("sendURL");
System.out.println(this.getClass() + " : postData : " + postData);
System.out.println(this.getClass() + " : gatewayURL : " + gatewayURL);
/* Process data and formulate a response.... */
String responseText = processedResponseText; // This processedResponseText was populated in the internal processing
String responseCode = processedResponseCode; // This processedResponseCode was populated in the internal processing
return "callingJSP";
}
私の AJAX Post - Success 関数の一部として、これら 2 つの変数 (responseText と responseCode) を呼び出し元の JSP に戻すにはどうすればよいですか?
どうもありがとう