Send a responseText to JavaScript from Struts 1.3 Action Class Method
Struts 1.3 Action class method
public ActionForward deleteIfesSystem(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws IOException {
Integer ifesSystemKey = Integer.parseInt(request.getParameter("ifesSystemKey"));
// Set IFES System properties
IFESystem ifeSystem = IFESystemManager.getIFESystem(ifesSystemKey);
String error = "OK";
try {
IFESystemManager.deleteIFESSystem(ifeSystem);
}
catch (HibernateException e) {
error = "IFES System cannot be deleted.";
}
response.getWriter().write(error);
response.getWriter().close();
return null;
}
JavaScript ajax function
function deleteOnClick() {
if (confirm("Do you want to delete the selected IFES System?")) {
var params = new Array();
params.push("action=deleteIfesSystem");
params.push("ifesSystemKey=" + ifesSystemGrid.getSelectedId());
var request = new ServerRequest( url + params.join("&"), null, false);
var xmlhttp = request.send();
debugger
if (xmlhttp.responseText == "OK") {
ifesSystemGrid.deleteRow(ifesSystemGrid.getSelectedId());
alert("IFES System deleted.");
}
else {
alert(xmlhttp.responseText);
}
}
}
Labels: JavaScript, Struts 1.3