Java - Web Servlet - Register

Creating a register class using web servlets in java.

Imports

import java.io.IOException;
import java.io.PrintWriter;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.RequestDispatcher;
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 javax.servlet.http.HttpSession;
import model.entities.UserAccount;
import model.entities.UserInfo;

Web Servlet

/* @author Steven Bartsch */
@WebServlet(urlPatterns = {"/register"})

Members

public class register extends HttpServlet{
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException{
        response.setContentType("text/html;charset=UTF-8");

        HttpSession session = request.getSession();

        String username     = (String)request.getParameter("username");
        String password     = (String)request.getParameter("password");
        String email        = (String)request.getParameter("email");
        String firstname    = (String)request.getParameter("firstname");
        String lastname     = (String)request.getParameter("lastname");
        String phone        = (String)request.getParameter("phone");
        String street       = (String)request.getParameter("street");
        String city         = (String)request.getParameter("city");
        String postalcode   = (String)request.getParameter("postalcode");
        Integer userlevel   = 1;

        UserAccount account = new UserAccount(userlevel,username,password,email);
        UserInfo info = new UserInfo(firstname,lastname,phone,street,city,postalcode);

        account.setUserlevel(userlevel);
        account.setUsername (username);
        account.setPassword (password);
        account.setEmail    (email);

        info.setFirstname   (firstname);
        info.setLastname    (lastname);
        info.setPhone       (phone);
        info.setStreet      (street);
        info.setCity        (city);
        info.setPostalcode  (postalcode);

        persist(account);
        persist(info);

        session.setAttribute("isRegister",true);

        RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher("/login.jsp");
        dispatcher.forward(request, response);   
    }

Persistence

    static public void persist(Object object){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("SecondAssignmentPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }

Overrides

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException{
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException{
        processRequest(request, response);
    }

    @Override
    public String getServletInfo(){
        return "Short description";
    }
}