【发布时间】:2017-07-27 20:13:20
【问题描述】:
我有一个基于 HTTP servlet 的网络应用程序。 这是对我的 servlet 的 JS 请求:
$.ajax({
type: "POST",
url: url,
xhrFields: {
withCredentials: false
},
data:{
"action" : action_type,
"fingerprint" : fingerprint,
"user_id" : user_id,
},
success: function(data) {
alert('sdp inviato!');
},
// vvv---- This is the new bit
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error, status = " + textStatus + ", " +
"error thrown: " + errorThrown
);
}
});
这是我的 servlet 代码:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action= request.getParameter("action");
UtenteModel um= new UtenteModel();
SDPLineModel sdpmodel= new SDPLineModel();
if (action.equals("CheckFingerprint")) {
String fingerprint = (String) request.getParameter("fingerprint");
String user_id = request.getParameter("user_id");
SDPLines sdpline = sdpmodel.findFingerprintNew(fingerprint, user_id);
if (sdpline == null) {
String message = "Fingerprint non valida!";
System.out.println("Fingerprint not found! ");
}
else {
System.out.println("Fingerprint found! ");
}
}
我的问题是:谁能告诉我一些修改我的 servlet 和 js 代码的例子,设置一个特定的响应数据(对于这两种情况,找到或未找到指纹)以及如何通过 JS 代码成功检查其值:函数(数据)?
【问题讨论】:
标签: javascript jquery http servlets