redirect a sql exception to an error page...
Hi guys,
i've a simple question (i think) but i have not found solution on google....
I want my jsf application can shows a specific page with stacktrace where a sql exception comes out from some statement.
How can i do it?
I've created this bean
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.SQLException;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.servlet.ServletException;
publicclass ErrorBean{
public String getStackTrace(){
FacesContext context = FacesContext.getCurrentInstance();
Map request = context.getExternalContext().getRequestMap();
Throwable ex = (Throwable) request.get("javax.servlet.error.exception");
StringWriter sw =new StringWriter();
PrintWriter pw =new PrintWriter(sw);
fillStackTrace(ex, pw);
return sw.toString();
}
privatestaticvoid fillStackTrace(Throwable t, PrintWriter w){
if (t ==null)
return;
t.printStackTrace(w);
if (tinstanceof ServletException){
Throwable cause = ((ServletException) t).getRootCause();
if (cause !=null){
w.println("Root cause:");
fillStackTrace(cause, w);
}
}elseif (tinstanceof SQLException){
Throwable cause = ((SQLException) t).getNextException();
if (cause !=null){
w.println("Next exception:");
fillStackTrace(cause, w);
}
}else{
Throwable cause = t.getCause();
if (cause !=null){
w.println("Cause:");
fillStackTrace(cause, w);
}
}
}
}
1) What i have to do in web.xml?
2) How can i "capture" sql exception and redirect user to an error page with stacktrace?
Please help me,thanks

