zoukankan      html  css  js  c++  java
  • dwr异常处理

    配置异常转换器:

    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>


    结果:








  • 相关阅读:
    如何快速建立自己的知识体系
    让你的网站变成灰色
    Java多线程-锁升级
    冰河正则大全
    Win硬盘/U盘设置图片
    MySQL——三范式
    MySQL——事务
    MySQL_explain
    HDFS的一些常用指令
    Hadoop集群的搭建准备
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/6944688.html
Copyright © 2011-2022 走看看