
Forgot Password of Application through servlet and jsp

package test.jithu;
import javax.servlet.*;
import java.sql.*;
import java.io.*;
public class LoginServlet implements Servlet {
Connection con;
Statement st;
ServletConfig sc;
ServletContext ctx;
String str,str1,str2;
public void init(ServletConfig sc)throws ServletException {
try{
this.sc=sc;
ctx=sc.getServletContext();
String Url=ctx.getInitParameter("dburl");
String User=ctx.getInitParameter("dbuser");
String Password=ctx.getInitParameter("dbpassword");
con=DriverManager.getConnection(Url,User,Password);
st=con.createStatement();
}catch(Exception e){
e.printStackTrace();
}
}
public ServletConfig getServletConfig(){
return null;
}
public String getServletInfo(){
return null;
}
public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException{
try{
String s=req.getParameter("cpwd");
String s1=req.getParameter("npwd");
ResultSet rs=st.executeQuery("select * from servlet6 where PASSWORD='"+s+"'");
PrintWriter pw=res.getWriter();
while(rs.next()){
str=rs.getString(1);
str1=rs.getString(2);
}
if(str1.equals(s)){
Statement st1=con.createStatement();
st1.executeUpdate("update servlet6 set password='"+s1+"' where username='"+str+"'");
pw.println("Password changed successfully");
}
}catch(SQLException se){
se.printStackTrace();
}
}
public void destroy(){
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.