首页 > 其他 > 详细

dwr异常处理

时间:2014-09-19 23:58:26      阅读:522      评论:0      收藏:0      [点我收藏+]

配置异常转换器:

dwr.xml:

<!-- 异常转换 -->
	<convert match="java.lang.Exception" converter="exception"/>
  	<convert match="java.lang.StackTraceElement" converter="bean"/>


UserService:

package com.demo.service;

import java.util.ArrayList;
import java.util.List;

import com.demo.model.User;

public class UserService {
	public static final String SUCCESS="success";
	public String add(User user){
		System.out.println(user);
		return SUCCESS;
	}
	public String deleted(int userId){
		throw new RuntimeException("删除出错了...");
	}
	public String update(User user){
		System.out.println("update:"+user);
		return SUCCESS;
	}
	public List<User> list(){
		List<User> users=new ArrayList<User>();
		users.add(new User(1,"aa"));
		users.add(new User(2,"bb"));
		users.add(new User(3,"cc"));
		return users;
	}
}


delete.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>user delete</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/util.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/UserService.js"></script>
<script type="text/javascript">
	UserService.deleted(11,{
		//回调函数  
		callback:callBack,
		  //异常处理
		  errorHandler:function(msg) {
			  alert(msg);
		  }
	});
	function callBack(result){
		alert(result);
	}
</script>
</head>
<body>

</body>
</html>


结果:

bubuko.com,布布扣







dwr异常处理

原文:http://blog.csdn.net/wobendiankun/article/details/39404421

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!