/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.octal.supinbank.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.octal.supinbank.entity.Person;
import net.octal.supinbank.entity.UserRole;
import net.octal.supinbank.service.CustomerService;
/**
*
* @author octal
*/
@WebServlet(name = "AddCustomerServlet", urlPatterns = {"/auth/admin/addCustomer"})
public class AddCustomerServlet extends HttpServlet {
// <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.getRequestDispatcher("../../addCustomer.jsp").forward(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 {
final String firstName = request.getParameter("firstname");
final String lastName = request.getParameter("lastname");
final String email = request.getParameter("email");
final String address = request.getParameter("address");
final String zipCode = request.getParameter("zipCode");
final String city = request.getParameter("city");
final String phoneNumber = request.getParameter("phoneNumber");
Person customer = new Person();
customer.setRole(UserRole.Customer);
customer.setAddress(address);
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setEmail(email);
customer.setPhone(phoneNumber);
customer.setCity(city);
customer.setZipCode(zipCode);
request.getSession().setAttribute("customer", customer);
response.sendRedirect(getServletContext().getContextPath() + "/auth/admin/addAccount");
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}