ajax.js
//1.点击删除时,弹出是否要删除xxx的信息,若确定则执行删除,否则取消操作
function disp_confirm(o)
{
var r=confirm("确认要删除吗?")
if (r==true){
var id=o.id;
$.post("emp-delete",{id:id},function(data,status){
if(status=="success"){
if(data=="1"){
alert("删除成功");
o.parentNode.parentNode.parentNode.removeChild(o.parentNode.parentNode);
}
if(data=="0"){
alert("删除失败");
}
}
});
}
return false;
}
// function abc(id){
//
//
// $.post("emp-delete",null,chuli);
// }
// function chuli(data,status){
// window.alert("进入回调函数");
// window.alert(status);
// if(status=="success"){
//
// }
// }
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<package name="default" extends="struts-default" namespace="/">
<action name="emp-*" class="empAction" method="{1}">
<result name="list">/WEB-INF/view/emp-list.jsp</result>
<result name="Golist" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
</package>
</struts>
java:
public short id;
private InputStream inputStream;
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public String delete(){
try {
empService.deleteEmp(id);
System.out.println("进入delete操作");
inputStream=new ByteArrayInputStream("1".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
try {
inputStream=new ByteArrayInputStream("0".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
return "Golist";
}