'How to detect the exception instance type in jsp
How to get confirm the exceptions types in jsp. I have printed Exception using ex.printStackTrace(response.getWriter()) method, but it is not professional way to show the exception to the user.
Suppose i am getting Connection expression. it arrives the exception but it will directly writes the exception on the document of HTML. it will doesn't gives/return value. I want show the professional error to the user like DB Connection Error only not lot of line code.
Solution 1:[1]
Sorry, I got solution on this issue. I have solved it as following code snippet.
<%@ page isErrorPage="true" import="java.util.*,java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<%
try{
throw exception; // it will gives exception as new, and you can get Exception type
}catch(SQLException ex){
out.println("<h3 style='color:red'>DataBase Connection Error</h3>");
}
catch (Exception e) {
e.printStackTrace(resopnse.getWriter());
}
%>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
