This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
public class Myservlet extends HttpServlet { String s,s1,s2; /** * Constructor of the object. */ public Myservlet() { super(); } /** * Destruction of the servlet. */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); Connection con; s=request.getParameter("t1"); s1=request.getParameter("t2"); Data d=new Data(); con=d.cc(); try { PreparedStatement ps=con.prepareStatement("select password from user1 where username=? "); ps.setString(1, s); ResultSet rs=ps.executeQuery(); while(rs.next())
{
s2=rs.getString(1); } }catch(SQLException x) { System.out.println(x); } if(s1.equals(s2)) { RequestDispatcher rd=request.getRequestDispatcher("/first.jsp"); rd.forward(request, response); } else { RequestDispatcher rd=request.getRequestDispatcher("/MyJsp.jsp"); rd.include(request, response); out.print("user and password are invalid"); } } /** * Initialization of the servlet. * * @throws ServletException if an error occure */ public void init() throws ServletException { // Put your code here } }
Data pacakage
package Mypack; import java.sql.*; public class Data { Connection con; public Connection cc() { try {