Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC loginDAO and Loginservlet

Have Programming Question? Ask it here!
 
 
 


Mumbai
loginDAO and Loginservlet
2 Answer(s)      a year and 2 months ago
Posted in : JDBC


how to make loginDAO and loginServlet?


Advertisement
View Answers

May 22, 2013 at 9:22 AM


userDAO
===================
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tcs.ignite.app.dao;

import com.tcs.ignite.app.beans.User;
import com.tcs.ignite.app.utils.ConnectionManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author 495944
 */
public class UserDAO {

    public void logUserIn(User user) {
        try {
            Connection con = new ConnectionManager().createConnection();
            String queryString = "select Username,password from register where Email='" + user.getEmail() + "'";
            PreparedStatement ps = con.prepareStatement(queryString);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                user.setRegistered(true);
                String password = rs.getString("password");
                if (password.equals(user.getPassword())) {
                    user.setName(rs.getString("Username"));
                }
            } else {
                user.setRegistered(false);
            }
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

         public boolean forgetpassword(User user){

        try {
            Connection con = new ConnectionManager().createConnection();

            String queryString ="update test.register set password=("+"'"+user.getNewpassword()+"'"+") where Email=("+"'"+user.getEmail()+"'"+")";
            System.out.println(queryString);
            PreparedStatement ps = con.prepareStatement(queryString);
            int rs = ps.executeUpdate();
            if(rs==1){
                return true;
            }else{
                return false;
            } 
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            return false;
        } catch (SQLException ex) {
            ex.printStackTrace();
            return false;
        }
    }  
}


May 22, 2013 at 9:23 AM


Login servlet
=======================
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tcs.ignite.app.servlets;

import com.tcs.ignite.app.beans.User;
import com.tcs.ignite.app.dao.UserDAO;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 495944
 */
@WebServlet(name = "Login1", urlPatterns = {"/Login1"})
public class Login1 extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /*
             * TODO output your page here. You may use following sample code.
             */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Login</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet Login at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.getSession().invalidate();
       response.sendRedirect("home.jsp");
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        User user = new User();
      user.setEmail(request.getParameter("inputEmail").trim());
        user.setPassword(request.getParameter("inputPassword1").trim());
        new UserDAO().logUserIn(user);
        if(user.isRegistered()){
            if(user.getName()!=null){
                request.getSession().setAttribute("user", user);
                request.getRequestDispatcher("home.jsp").forward(request, response);
                }
            else{
                request.setAttribute("msg", "Wrong Password");
                request.getRequestDispatcher("home.jsp").forward(request, response);
//                response.sendRedirect("index.jsp");
            }
        }else{
            request.setAttribute("msg", "User does not exist.");
            request.getRequestDispatcher("home.jsp").forward(request, response);
//            response.sendRedirect("index.jsp");
        }

    }
    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}


Related Tutorials/Questions & Answers:
loginDAO and Loginservlet
loginDAO and Loginservlet  how to make loginDAO and loginServlet?   userDAO /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.tcs.ignite.app.dao; import
Loginservlet not being called
Loginservlet not being called  Hi, I have created a simple login page using jsp,on submit it calls the loginservlet,Everything was working fine when I run the jsp in eclipse,on clickin the submit button login servlet was called
Advertisements
Java client posting to a servlet - Development process
javax.servlet.http.*; public class LoginServlet extends HttpServlet{ public void...(""); } } web.xml file for this program: Hello LoginServlet Hello /LoginServlet For more information on servlets visit to : http
Spring 4: Login Form using Spring MVC and Hibernate Example
net.roseindia.model.*; public interface LoginDAO{ public boolean... org.hibernate.Query; import java.util.List; @Repository("loginDAO") public class LoginDAOImpl implements LoginDAO{ @Resource(name
http status 500 error in tomcat 6 while using eclipse helios
*; import java.io.*; public class LoginServlet extends HttpServlet{ public void init... org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet LoginServlet threw
http status 500 error in tomcat 6 while using eclipse helios
*; import java.io.*; public class LoginServlet extends HttpServlet{ public void init... org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet LoginServlet threw
http status 500 error in tomcat 6 while using eclipse helios
*; import java.io.*; public class LoginServlet extends HttpServlet{ public void init... org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet LoginServlet threw
http status 500 error in tomcat 6 while using eclipse helios
*; import java.io.*; public class LoginServlet extends HttpServlet{ public void init... org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet LoginServlet threw
http status 500 error in tomcat 6 while using eclipse helios
*; import java.io.*; public class LoginServlet extends HttpServlet{ public void init... org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet LoginServlet threw
File size limit - JSP-Servlet
LoginServlet .auth.LoginServlet UploadServlet.../* LoginServlet /login
Need Help-How to store input parameter in DB through Java Bean - JSP-Servlet
javax.servlet.*; import javax.servlet.http.*; public class LoginServlet extends...: Password: web.xml: one LoginServlet one /tmp
Using Servlets, JSP for Online Shopping
? JSP <form action="LoginServlet "method="post" > <table>..., response); } } }   Login.jsp: <form action="LoginServlet... javax.servlet.http.*; public class LoginServlet extends HttpServlet{ public void doPost
login example
Page</title> </head> <body> <form action="LoginServlet">... javax.servlet.http.HttpSession; /** * Servlet implementation class LoginServlet */ public class LoginServlet extends HttpServlet { public void doGet(HttpServletRequest
login example
Page</title> </head> <body> <form action="LoginServlet">... javax.servlet.http.HttpSession; /** * Servlet implementation class LoginServlet */ public class LoginServlet extends HttpServlet { public void doGet(HttpServletRequest
How does this example work even if no oracle to be used and only access is available?
; /** * Servlet implementation class LoginServlet */ public class LoginServlet extends
How Map the First_Servlet to Second_Servlet - JSP-Servlet
class LoginServlet extends HttpServlet{ public void doGet(HttpServletRequest... Page web.xml: one LoginServlet one /tmp submit.jsp
Also HTTP Status 404 - /Login/userdetail.java
LoginServlet extends HttpServlet{ public void doPost(HttpServletRequest
unable to retrive the data from mysql using servlet using jdbc driver
unable to retrive the data from mysql using servlet using jdbc driver  Hi, i have a servlet program..to verify the login and redirect to correct html page on verification. public class LoginServlet extends HttpServlet implements
Servlets - JSP-Servlet
javax.servlet.http.*; import java.io.*; import java.sql.*; public class loginservlet
Struts - Struts
javax.servlet.http.*; import java.io.*; import java.sql.*; public class loginservlet
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?
implementationStatus; private String subSystem; private LoginDAOImpl loginDAO = new
Servlet-JSP Mapping - JSP-Servlet
class LoginServlet extends HttpServlet{ public void doGet(HttpServletRequest... Page web.xml: one LoginServlet one /tmp submit.jsp issue.jsp
Servlet-JSP Mapping - JSP-Servlet
class LoginServlet extends HttpServlet{ public void doGet(HttpServletRequest... Page web.xml: one LoginServlet one /tmp submit.jsp issue.jsp
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection - JSP-Servlet
*; /** * @author Santosh */ public class LoginServlet extends GenericServlet
java server programming : servlet - JSP-Servlet
(""); out.println("Servlet LoginServlet"); out.println
HTTP Status 404 - /Login/userdetail.java
java.sql.*; public class LoginServlet extends HttpServlet{ public void
Servlets
.*; public class LoginServlet extends HttpServlet { public void Service
java multiple users with single connection - JSP-Servlet
*; public class LoginServlet extends HttpServlet{ public void doPost
Passing Parameter Using Html Form
;/htmlform/LoginServlet">   <p> Username  <
 

 

 

DMCA.com