Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to redirec to to HTML if exception ocurred
- public class DBConection{
- Connection con = null;
- public DBConnection() throws RuntimeException{
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- String user = "root";
- String pass = "12345";
- String db = "java";
- con = DriverManager.getConnection("jdbc:mysql://localhost/" + db, user, pass);
- }catch (ClassNotFoundException ex) {
- throw new RuntimeException();
- }catch (SQLException ex) {
- throw new RuntimeException();
- }
- }
- }
- public class ElectionsServlet extends HttpServlet {
- private static final long serialVersionUID = 1L;
- private static final String RETURN_PAGE = "index.jsp";
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- DBConnection con = new DBConnection();
- response.sendRedirect(RETURN_PAGE);
- }
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- try{
- DBConnection con = new DBConnection();
- }catch(Exception e){
- response.sendRedirect(RETURN_PAGE);
- }
- }
Add Comment
Please, Sign In to add comment