Guest User

Untitled

a guest
Sep 10th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. How to redirec to to HTML if exception ocurred
  2. public class DBConection{
  3. Connection con = null;
  4. public DBConnection() throws RuntimeException{
  5. try {
  6. Class.forName("org.gjt.mm.mysql.Driver");
  7. String user = "root";
  8. String pass = "12345";
  9. String db = "java";
  10. con = DriverManager.getConnection("jdbc:mysql://localhost/" + db, user, pass);
  11. }catch (ClassNotFoundException ex) {
  12. throw new RuntimeException();
  13. }catch (SQLException ex) {
  14. throw new RuntimeException();
  15. }
  16. }
  17. }
  18.  
  19. public class ElectionsServlet extends HttpServlet {
  20. private static final long serialVersionUID = 1L;
  21. private static final String RETURN_PAGE = "index.jsp";
  22.  
  23. public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  24. DBConnection con = new DBConnection();
  25. response.sendRedirect(RETURN_PAGE);
  26. }
  27. }
  28.  
  29. public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  30. try{
  31. DBConnection con = new DBConnection();
  32. }catch(Exception e){
  33. response.sendRedirect(RETURN_PAGE);
  34. }
  35. }
Add Comment
Please, Sign In to add comment