-1
Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","12345");
            Statement st =con.createStatement();
            String mi = "select * from empinfo where EEmailID = '"+email+"'";
            
            ResultSet rs = st.executeQuery(mi);
            if(rs.next()) {
            if(email.equals(rs.getString("EEMailID"))){
                 // Generate a random OTP
        Random random = new Random();
        int otp = 100000 + random.nextInt(900000);

        // Send OTP through email Calling Function
        sendEmail(otp, email);

        // Store OTP in the session for Verification
        HttpSession session = request.getSession();
        session.setAttribute("OTP", Integer.toString(otp));
        session.setAttribute("eemail",email);

        // Redirect the user to the OTP verification page
        response.sendRedirect("otp.jsp");
            }}
            else{
                out.println("Enter Registered Email Id only");
                RequestDispatcher dis= getServletContext().getRequestDispatcher("/forgotpassword.jsp");
                dis.include(request, response);
                }

It is showing this in the output:-

Enter Registered Email Id only

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="bootstrap-4.0.0-dist/css/bootstrap.css" rel="stylesheet" type="text/css"/>
        <link href="bootstrap-4.0.0-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
        <title>JSP Page</title>
    </head>
    <body>
       
        <center>
        <form action="OTPLoginServlet" method="post">
            <label for="email">Email:</label>
            <input type="email" id="email" name="email"><br><br>
            <input type="submit" value="Submit">
        </form>
    </center>
    </body>
</html>

above is the code present in forgotpassword.jsp that is not executing but only showing it. So, what can I do to solve this error?

Diana
  • 1
  • 3

1 Answers1

0

Use the below approach.

Instead of retrieving the object of 'RequestDispatcher' from getServletContext(), retrieve the same object from the HttpServletRequest like -

RequestDispatcher rd = request.getRequestDispatcher("/forgotpassword.jsp");
    
rd.include(request, response);
  • I tried this too but it was giving same error that's why used above code but it didn't help. – Diana Mar 21 '23 at 17:42