Note that there are some explanatory texts on larger screens.

plurals
  1. POReset password, if anyone forgot his password
    primarykey
    data
    text
    <p>I am trying to create reset password in html. When i submit reset button, it will go to ResetPasswordServlet. Then the controller will go from servlet to CustomerDAO. There, it need to update the database. I created database connection also. I tested it but it is not working (not updated in the database.) I know that there is something wrong with my code but i am unable to figure it out.</p> <p>Here is my code. Can anybody help me to figure it out where i am doing wrong. Thank You so much.</p> <h1>ResetPasswordServlet</h1> <pre><code>package com.dao; /** * @see HttpServlet#HttpServlet() */ public ResetPasswordServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub PrintWriter out = response.getWriter(); out.println("&lt;html&gt;&lt;body&gt;"); out.println("&lt;center&gt;&lt;h2&gt;Reset your password&lt;/h2&gt;&lt;/center&gt;"); out.println("&lt;form action=ResetPassword method=post&gt;"); out.println("Enter your username &lt;input type=text name=LoginId&gt;&lt;br&gt; "); out.println("Enter your new Password&lt;input type=password name=password&gt;&lt;br&gt;"); out.println("Confirm your new Password &lt;input type=password name=confirm&gt;&lt;br&gt;"); out.println("&lt;input type=submit value=RESET&gt;"); out.println("&lt;/form&gt;"); out.println("&lt;/body&gt;&lt;/html&gt;"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub CustomerDAO customerDAO = new CustomerDAO(); String loginId = request.getParameter("LoginId"); String loginPassword = request.getParameter("password"); String confirmPassword = request.getParameter("confirm"); Login login = customerDAO.resetPassword(loginId, loginPassword, confirmPassword); } </code></pre> <p>}</p> <h1>CustomerDAO</h1> <pre><code>public Login resetPassword(String loginId, String loginPassword, String confirmPassword) { Login login = null; try { BaseDAO baseDAO = new BaseDAO(); Connection c =baseDAO.getConnection(); String query = "update test.Customer set LoginPassword=?, ConfirmPassword=? where LoginId=?" ; PreparedStatement ps = c.prepareStatement(query); ps.setString(1, loginId); ps.setString(2, loginPassword); ps.setString(3, confirmPassword); System.out.println(loginId); System.out.println(loginPassword); System.out.println(confirmPassword); int i = ps.executeUpdate(); if(i==1) { System.out.println("record updated successfully"); }else { System.out.println("record not updated."); } c.close(); }catch(Exception e) { e.printStackTrace(); } return login; } </code></pre> <p>I did some changes in the code.</p> <p>When i submit the button, it is not showing any error and also not updated in the database. In CustomerDAO, the else block is executed and the record not updated is printed. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload