Issue
I have a servlet with following code
@WebServlet(urlPatterns = "/attachmentUpload.do")
@MultipartConfig
public class AttachmentUploadServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (operationName != null && operationName.equalsIgnoreCase("attachToSNOW")) {
JSONArray runbookRows = new JSONArray(request.getParameter("runbook"));
LOGGER.log(Level.INFO, "runbook rows:{0}", runbookRows.toString());
}
}
}
and ajax call from jsp like this
$.ajax({
url: "attachmentUpload.do",
method: "post",
data: {"operationName": "attachToSNOW",
"runbook": JSON.stringify(rowArray)
},
success: function (data) {
console.log("ajax called");
},
error: function (msg) {
console.log("Couldn't attach file");
}
});
The ajax call just doesn't seem to hit the servlet where my application is deployed(tomcat 8) whereas the same works in a local tomcat attached to Netbeans.
Am totally clueless as to what is the issue.
Stuck on this for couple of weeks now
EDIT The real issue was, when I was opening a child jsp from parent jsp. In child JSP I was dumping some data into a temp file that would later on be pushed to a web service, the ajax call mentioned was in child jsp. and I was getting no logs in tomcat stdout(also so temp file creation) , hence I understood that part of the code wasn't being reached.
as soon as I changed the ajax call to below, things started working :)
$.ajax({
url: "attachmentUpload.do",
method: "post",
**async: false,
cache: false,**
data: {"operationName": "attachToSNOW",
"runbook": JSON.stringify(rowArray)
},
success: function (data) {
window.opener.log("ajax called");
},
error: function (msg) {
console.log("Couldn't attach file");
}
});
async and cache seem to have done the magic
Solution
adding async and cache solved my problem
$.ajax({
url: "attachmentUpload.do",
method: "post",
async: false,
cache: false,
data: {"operationName": "attachToSNOW",
"runbook": JSON.stringify(rowArray)
},
success: function (data) {
window.opener.log("ajax called");
},
error: function (msg) {
console.log("Couldn't attach file");
}
});
Answered By - Just Another Developer
Answer Checked By - Willingham (JavaFixing Volunteer)