오류 메세지로는 ERR-001 과 같이 오류 형태의 코드가 있고, INFO-001 과 같이 정보 메세지가 있으므로 오류만 필터링하여 아래와 같이 alert 를 띄울 수 있습니다.
<head>
<script>
$(function(){
$("#myUpload").IBUpload({
viewType:"icon",
iconMode :"detail",
onMessage: function(msgID, msg) {
if (msgID.substring(0, 3) == "ERR") {
// 오류는 메세지로 표시
alert(msg + "\n\n" + "error : " + msgID);
} else {
//alert(msg); // 일반 정보 메세지는 숨김
}
}
});
});
</script>
</head>
[오류와 정보 메시지를 분리하여 alert 띄우기]
Servelet에서 Exception 관련 에러 메시지는 Json 형식으로 아래와 같이 구성됩니다.
- Json 형식 : {"error":"오류가 발생하였습니다."}
try {
} catch (Exception ex) {
Map msg = new HashMap();
msg.put("error","오류가 발생하였습니다.");
//오류에 대한 자세한 내역이 필요하다면 다음과 같이 사용하세요.
//String exMsg = ex.getMessage();
//msg.put("error",exMsg);
out.print(org.json.simple.JSONValue.toJSONString(msg));
}
[Servelet에서 Exception 처리(jsonSimple lib 사용)]