我想在运行时处理oracle disconnect的异常。现在我在web.xml中的当前代码是
<error-page>
<exception-type>javax.transaction.xa.XAException</exception-type>
<location>/ExceptionHandler.do</location>
</error-page>
目前,无法处理该异常。让我知道你的意见。
答案 0 :(得分:0)
嗨Zay Ya,
将您的数据库连接代码放入try catch块,并在catch块中返回一些字符串 package com.test.tree;
import java.util.Comparator;
import java.util.TreeMap;
public class TestTreeMap{
public static void main(String[] args) {
TreeMap tree=new TreeMap(new TestComparator());
T1 t1=new T1(10, 20);
T2 t2=new T2(10,21);
tree.put(t1, 23);
tree.put(t2, 24);
}
}
class T1 {
int x,y;
public T1(int x, int y) {
super();
this.x = x;
this.y = y;
}
}
class T2 {
int x,y;
public T2(int x,int y) {
super();
this.x = x;
this.y = y;
}
}
class TestComparator implements Comparator{
@Override
public int compare(Object o1, Object o2) {
System.out.println("hi im called");
T1 t1=(T1)o1;
T2 t2=(T2)o2;
return t1.x-t2.y;
}
}
。
例如: -
"error"
现在将此处理到 try{
// Database Connectivity code here
} catch(javax.transaction.xa.XAException ex){
ex.printStackTrace();
return "error";
}
文件
struts.xml