lundi 25 juin 2018

Use sweetalert javascript function in jsp

I am working on a login page that needs to show an alert of successful login before redirecting to another html page. I have written my code using jsp. I want to use sweet alert for the same but doesn't seem to be working.

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
     <script
        src="https://code.jquery.com/jquery-3.3.1.js"
        integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
        crossorigin="anonymous"></script>
     <script src="sweetalert2.all.min.js"></script>
        <!-- Optional: include a polyfill for ES6 Promises for IE11 and Android browser -->
        <script src="https://unpkg.com/promise-polyfill"></script>
        <link rel="stylesheet" href="sweetalert2.min.css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
 <%
     String account_no="1";
     int old_balance=0;
     int new_balance=0;
     Connection con = null;
     PreparedStatement pst=null;
     ResultSet rs = null;
     int amount=Integer.parseInt(request.getParameter("deposit_amount"));

     try {


             Class.forName("oracle.jdbc.driver.OracleDriver");
             con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE", "HR", "HR");


             pst=con.prepareStatement("SELECT * FROM CUSTOMER WHERE ACCOUNT_NO=?");
             pst.setString(1,account_no);
             rs=pst.executeQuery();

             while(rs.next())
             {
             old_balance=Integer.parseInt(rs.getString(3));
             out.println(old_balance);
             }

            new_balance=old_balance+amount; 
            out.println(new_balance);
            pst=con.prepareStatement("UPDATE CUSTOMER SET BALANCE=? WHERE ACCOUNT_NO=?");
            pst.setInt(1,new_balance);
            pst.setString(2,account_no);
            pst.executeUpdate();

 %>
            <script>
                $(document).ready(function(){
                    swal(
                        'The Internet?',
                        'That thing is still around?',
                        'question'
                        );
                });
            </script>
            <jsp:forward page="home2.html"></jsp:forward>
            <%

            }


            catch (Exception e) {
                out.println(e.getMessage());
           }


        %>
    </body>
</html>

In the script i have tried to use sweetalert but am unable to execute the same. The database part works fine but this jsp shows blank on webpage and even the forward doesnt work




Aucun commentaire:

Enregistrer un commentaire