Advertisement
Guest User

Untitled

a guest
May 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. import java.io.*;
  2. import java.text.*;
  3. import java.util.*;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6. import java.sql.*;
  7. import BookStoreBeans.*;
  8.  
  9. public class RegisterTry extends HttpServlet
  10. {
  11.     public void doPost(HttpServletRequest req, HttpServletResponse res)
  12.     throws IOException, ServletException
  13.     {
  14.         PrintWriter out = res.getWriter();     
  15.        
  16.  
  17.         //delcare two objects to represent the log in user
  18.         String FN = null;
  19.         String LN = null;      
  20.         String EM = null;
  21.         String PD = null;
  22.         String ST = null;
  23.         String CI = null;
  24.         String STA = null;
  25.         String ZC = null;
  26.         String PH = null;
  27.         String PWDH = null;
  28.  
  29.         //get the current session
  30.         HttpSession session = req.getSession();
  31.        
  32.         FN = req.getParameter("firstName");
  33.         LN = req.getParameter("lastName");
  34.         EM = req.getParameter("email");
  35.         PD = req.getParameter("password1");
  36.         ST = req.getParameter("streetAddress1");
  37.         CI = req.getParameter("city");
  38.         STA = req.getParameter("state");
  39.         ZC = req.getParameter("zip");
  40.         PH = req.getParameter("phone");
  41.         PWDH = req.getParameter("passwordHint");
  42.        
  43.         //Invalidate an old session if it exists
  44.         //session.invalidate();
  45.  
  46.         //get a fresh session
  47.         //session = request.getSession();
  48.    
  49.         Customer customer = new Customer();
  50.        
  51.         customer.setfname(FN);
  52.                 customer.setlname(LN);
  53.                 customer.setemail(EM);
  54.                 customer.setpassword(PD);
  55.                 customer.setuserid(1);
  56.                 customer.setstreet(ST);
  57.                 customer.setcity(CI);
  58.                 customer.setstate(STA);
  59.                 customer.setzipcode(ZC);
  60.                 customer.setphone(PH);
  61.                 customer.setpasswordhint(PWDH);
  62.  
  63.                 session.setAttribute("customer", customer);
  64.                
  65.         String insertSql = "INSERT INTO customer (fname, lname, street, city, state, zipcode, phone, email, passwd, passwordhint) "
  66.         + "VALUES ('" + FN + "', '"
  67.                 + LN + "', '" + ST + "', '" + CI + "', '" + STA
  68.                 + "', '" + ZC + "', '" + PH + "', '" + EM + "', '"
  69.                 + PD + "', '" + PWDH + "');";
  70.        
  71.         String sqlSearch = "Select * from customer where customer.email = '" + EM + "';";
  72.  
  73.         String URL = "jdbc:postgresql:Chappel";
  74.  
  75.         try
  76.         {
  77.             Class.forName("org.postgresql.Driver");
  78.             Connection con = DriverManager.getConnection(URL, "postgres", "user");
  79.             Statement stmt = con.createStatement();
  80.             stmt.executeQuery(insertSql);
  81.                
  82.                
  83.                
  84.            
  85.            
  86.         }
  87.         catch(Exception sqle)
  88.         {
  89.             res.sendRedirect("/Chappel/jsp/thankyou.jsp");
  90.                        
  91.         }
  92.             return;
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement