The error prompt box (DWR) is displayed for the web program. The cause remains to be considered

Source: Internet
Author: User

During the project process, we found that the DWR method was used to call the remote method. Sometimes the Alert box appears inexplicably with the content "error ". If a null value or a direct error is returned, corresponding exception handling must be performed:
Remote. Method (Params, function (data ){
// The client logic after the server executes, as shown in figure
Alert ("data returned after server execution:" + data );
});

Remote> processing class, method> method in class, Params> parameters in method, function> callback method, data> data returned by callback method.

The first parameter is the data that the client transmits to the server. The last parameter is a callback function. Because the JS Code generated by the server based on the Java object is:
Remote. method = function (P0, callback ){
DWR. Engine. _ execute (remote. _ path, 'remote', 'method', P0, callback );
}
If the remote method throws an exception when processing the request, DWR will only give alert ("error") a simple error, so we need to figure out how to actively capture this error, more friendly display to users. Therefore, if a remote call exception occurs

The Alert ("error") is actually the global error handling of DWR. You can use DWR. Engine. seterrorhandler (errorhandler) to change its default behavior, such
Function errh (errorstring, exception ){
Alert ("indicates the custom global error message. ");
}
DWR. Engine. seterrorhandler (errh );
We may rarely do this because the global error processing cannot meet personalized remote calls. We can write the error handling errorhandler in the remote call function parameters. Looking back at the previous callback, when it is a function, it is a processing function after a successful call. It can also be an object containing several functions. In this case, the remote call should be written as follows:
Remote. Method (Params ,{
Callback: function (data) {// processing function when the call is successful
// The client logic after the server executes, as shown in figure
Alert ("data returned after server execution:" + data );
},
Errorhandler: function (errorstring, exception) {// when an exception occurs
Alert ('error occurred when modifying XXX. Please check XXX cloud: '+ errorstring)
}
}
);
More deeply, callback cannot include the other two function attributes: predictionhandler, warninghandler, and texthtmlhandler. Without the exceptionhandler handler, The errorhandler function will be applied, and the JS error in the callback function will also be executed by errorhandler.
Again, it can be stored in DWR. configure convert related to exceptions in XML, such as: <convert match = "Java. lang. exception "converter =" exception "/>. Use errorhandler's errorstring and exception to obtain more detailed information.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.