Java代码
public String deleteUser(String id) {
if(!users.keySet().contains(id))
throw new UserException("要删除的用户不存在");
users.remove(id);
return "删除成功";
}
dwr.xml
dwr.xml文件添加如下配置
<!-- 处理异常 -->
<convert converter="exception" match="java.lang.Exception"/>
<convert converter="bean" match="java.lang.StackTraceElement"/>
jsp文件接收异常信息
//删除用户
$("#deletebtn").on("click",function(){
var userId = $("#deleteUserId").val();
//调用java代码,删除用户
UserService.deleteUser(userId,{
callback : function(data){
console.log(data);
},
errorHandler : function(msg, e) {
//msg:异常信息,e:异常对象
alert(msg);
}
});
listUsers();
});