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



Home Answers Viewqa JDBC registrationDAO& registrationservlet

Have Programming Question? Ask it here!
 
 
 


Mumbai
registrationDAO& registrationservlet
1 Answer(s)      11 months ago
Posted in : JDBC


how to make registrationDAO and registration servlet?


Advertisement
View Answers

May 22, 2013 at 9:15 AM


RegsDAO
==============
/*
 * 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.Registration;
import com.tcs.ignite.app.utils.ConnectionManager;
import java.io.PrintWriter;
import java.sql.*;
/**
 *
 * @author ignite027
 */
public class RegistrationDAO {
    public boolean registration(Registration reg){
        try{
             PrintWriter out = null;
            Connection con=new ConnectionManager().createConnection();
            String qstring1="insert into register values (?,?,?,?)";
            PreparedStatement ps=con.prepareStatement(qstring1);
            ps.setString(1,reg.getName());
            ps.setString(2,reg.getEmail());
            ps.setString(3, reg.getPassword());
            ps.setString(4, reg.getPhonenumber());

       ps.executeUpdate();


             ps.close();
             return true;
        }catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            return false;
        } catch (SQLException ex) {
            ex.printStackTrace();
            return false;
        }

    }

    private boolean isRegistered(boolean b) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}

======================
Regis 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.Registration;
import com.tcs.ignite.app.dao.RegistrationDAO;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author ignite027
 */
public class Regis 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 Regis</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet Regis 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 {
        processRequest(request, response);
    }

    /**
     * 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 {
       PrintWriter out=response.getWriter();
       Registration reg=new Registration();
       reg.setName(request.getParameter("inputName").trim());
        reg.setEmail(request.getParameter("inputEmail").trim());
         reg.setPassword(request.getParameter("inputConfirmPassword").trim());
         reg.setPhonenumber(request.getParameter("inputMobilenumber").trim());
            boolean registered = new RegistrationDAO().registration(reg);
            if(registered){                             
                request.setAttribute("msg", "You are registered Successfully");
                request.getRequestDispatcher("home.jsp").forward(request, response);            
        }else{
            request.setAttribute("msg", "Not Registered Successfully");
           request.getRequestDispatcher("register.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:
registrationDAO& registrationservlet
registrationDAO& registrationservlet  how to make registrationDAO...*; /** * * @author ignite027 */ public class RegistrationDAO { public...(request.getParameter("inputMobilenumber").trim()); boolean registered = new RegistrationDAO
 

 

 

DMCA.com