title: Registration system based on JSP with MySQL connection - null's in db
body: <p>i'm trying to create a registration system using jsp, beans and servlets. Registration process seems to be ok, but everytime data is supposed to be stored into database, rows are only filled with NULLs. Im a newbie in this subject so i would really apreciate your help!
  Here is the code of this "system":</p>
  
  <p>ragister.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;body &gt;
  &lt;form action="/Ragis/proces.jsp" method=post&gt;
  &lt;center&gt;
  &lt;table cellpadding=2 cellspacing=1 border="1" bgcolor="lightblue"&gt;
  &lt;th bgcolor="lightblue" colspan=2&gt;
  &lt;font size=5&gt;User Registration&lt;/font&gt;
  &lt;br&gt;
  &lt;font size=2 color="red"&gt;&lt;sup&gt;*&lt;/sup&gt; Required Fields&lt;/font&gt;
  &lt;/th&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt; 
  &lt;b&gt;First Name&lt;sup&gt;*&lt;/sup&gt;&lt;/b&gt; 
  &lt;br&gt;
  &lt;input type="text" name="firstName" value="" size=20 maxlength=20&gt;&lt;/td&gt;
  &lt;td  valign=top&gt;
  &lt;b&gt;Last Name&lt;sup&gt;*&lt;/sup&gt;&lt;/b&gt;
  &lt;br&gt;
  &lt;input type="text" name="lastName" value="" size=15 maxlength=20&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt;
  &lt;b&gt;E-Mail&lt;sup&gt;*&lt;/sup&gt;&lt;/b&gt; 
  &lt;br&gt;
  &lt;input type="text" name="email" value="" size=25  maxlength=125&gt;
  &lt;br&gt;&lt;/td&gt;
  &lt;td  valign=top&gt;
  &lt;b&gt;Cell Nr(9 fig.)&lt;sup&gt;*&lt;/sup&gt;&lt;/b&gt; 
  &lt;br&gt;
  &lt;input type="text" name="zip" value="" size=10  maxlength=9&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top colspan=2&gt;
  &lt;b&gt;User Name&lt;sup&gt;*&lt;/sup&gt;&lt;/b&gt;
  &lt;br&gt;
  &lt;input type="text" name="userName" size=20 value=""  maxlength=10&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt;
  &lt;b&gt;Password&lt;sup&gt;*&lt;/sup&gt;&lt;/b&gt; 
  &lt;br&gt;
  &lt;input type="password" name="password1" size=10 value="" maxlength=10&gt;&lt;/td&gt;
  &lt;td  valign=top&gt;
  &lt;b&gt;Confirm Password&lt;sup&gt;*&lt;/sup&gt;&lt;/b&gt;
  &lt;br&gt;
  &lt;input type="password" name="password2" size=10 value="" maxlength=10&gt;&lt;/td&gt;
  &lt;br&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td  align=center colspan=2&gt;
  &lt;input type="submit" value="Submit"&gt; &lt;input type="reset"  
  value="Reset"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/center&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>proces.jsp</p>
  
  <pre><code>&lt;%@ page language="java" %&gt;
  &lt;%@ page import="java.util.*" %&gt;
  &lt;%! 
  
  %&gt;
  &lt;jsp:useBean id="formHandler" class="test.FormBean" scope="request"&gt;
  &lt;jsp:setProperty name="formHandler" property="*"/&gt;
  &lt;/jsp:useBean&gt;
   &lt;%   if (formHandler.validate()) {   
  %&gt;
  
  &lt;html&gt;
  &lt;body&gt;
  &lt;center&gt;
  &lt;form action="/Ragis/Registration" method=post&gt;
      &lt;input type="submit" name="Submit" value="Submit" style="background-color:#49743D;font-weight:bold;color:#ffffff;"/&gt;
      &lt;/form&gt;
  
  &lt;table cellpadding=1 cellspacing=1 border="1" &gt;
  &lt;th bgcolor="lightblue" colspan=2&gt;
  &lt;font size=5&gt;Almost done! Just press SUBMIT to finish the registration procedure!&lt;/font&gt;
  &lt;/th&gt;
  &lt;font size=4&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt; 
  &lt;b&gt;First Name&lt;/b&gt; 
  &lt;br&gt;
  &lt;jsp:getProperty name="formHandler" property="firstName"/&gt;
  &lt;/td&gt;
  &lt;td valign=top&gt;
  &lt;b&gt;Last Name&lt;/b&gt;
  &lt;br&gt;
  &lt;jsp:getProperty name="formHandler" property="lastName"/&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt;
  &lt;b&gt;E-Mail&lt;/b&gt; 
  &lt;br&gt;
  &lt;jsp:getProperty name="formHandler" property="email"/&gt;
  &lt;br&gt;&lt;/td&gt;
  &lt;td valign=top&gt;
  &lt;b&gt;Cell Nr(9 fig.)&lt;/b&gt; 
  &lt;br&gt;
  &lt;jsp:getProperty name="formHandler" property="zip"/&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top colspan=2&gt;
  &lt;b&gt;User Name&lt;/b&gt;
  &lt;br&gt;
  &lt;jsp:getProperty name="formHandler" property="userName"/&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/font&gt;
  &lt;/table&gt;
  &lt;/center&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  &lt;%
     }  else {
  %&gt;
      &lt;jsp:forward page="retry.jsp"/&gt;
  &lt;%
     }
  %&gt;
  </code></pre>
  
  <p>retry.jsp</p>
  
  <pre><code>&lt;jsp:useBean id="formHandler" class="test.FormBean" scope="request"/&gt;
  &lt;html&gt; 
  &lt;body&gt;
  &lt;form action="/Ragis/proces.jsp" method=post&gt;
  &lt;center&gt;
  &lt;table cellpadding=4 cellspacing=2 border=0&gt;
  &lt;th bgcolor="lightblue" colspan=2&gt;
  &lt;font size=5&gt;User Registration&lt;/font&gt;
  &lt;br&gt;
  &lt;font size=2 color="red"&gt;&lt;sup&gt;*&lt;/sup&gt; Required Fields &lt;/font&gt;
  &lt;/th&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt; 
  &lt;B&gt;First Name&lt;sup&gt;*&lt;/sup&gt;&lt;/B&gt; 
  &lt;br&gt;
  &lt;input type="text" name="firstName" 
  value='&lt;%=formHandler.getFirstName()%&gt;' size=15 maxlength=20&gt;
  &lt;br&gt;&lt;font size=2 
  color=red&gt;&lt;%=formHandler.getErrorMsg("firstName")%&gt;&lt;/font&gt;
  &lt;/td&gt;
  &lt;td  valign=top&gt;
  &lt;B&gt;Last Name&lt;sup&gt;*&lt;/sup&gt;&lt;/B&gt;
  &lt;br&gt;
  &lt;input type="text" name="lastName" 
  value='&lt;%=formHandler.getLastName()%&gt;' size=15 maxlength=20&gt;
  &lt;br&gt;&lt;font size=2 
  color=red&gt;&lt;%=formHandler.getErrorMsg("lastName")%&gt;&lt;/font&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt;
  &lt;B&gt;E-Mail&lt;sup&gt;*&lt;/sup&gt;&lt;/B&gt; 
  &lt;br&gt;
  &lt;input type="text" name="email" value='&lt;%=formHandler.getEmail()%&gt;' 
  size=25  maxlength=125&gt;
  &lt;br&gt;&lt;font size=2 color=red&gt;&lt;%=formHandler.getErrorMsg("email")%&gt;&lt;/font&gt;
  &lt;/td&gt;
  &lt;td  valign=top&gt;
  &lt;B&gt;Cell Nr(9 fig.)&lt;sup&gt;*&lt;/sup&gt;&lt;/B&gt; 
  &lt;br&gt;
  &lt;input type="text" name="zip" value='&lt;%=formHandler.getZip()%&gt;' size=5  
  maxlength=9&gt;
  &lt;br&gt;&lt;font size=2 color=red&gt;&lt;%=formHandler.getErrorMsg("zip")%&gt;&lt;/font&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top colspan=2&gt; 
  &lt;B&gt;User Name&lt;sup&gt;*&lt;/sup&gt;&lt;/B&gt;
  &lt;br&gt;
  &lt;input type="text" name="userName" size=10 
  value='&lt;%=formHandler.getUserName()%&gt;'  maxlength=10&gt;
  &lt;br&gt;&lt;font size=2 
  color=red&gt;&lt;%=formHandler.getErrorMsg("userName")%&gt;&lt;/font&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td valign=top&gt;
  &lt;B&gt;Password&lt;sup&gt;*&lt;/sup&gt;&lt;/B&gt; 
  &lt;br&gt;
  &lt;input type="password" name="password1" size=10 
  value='&lt;%=formHandler.getPassword1()%&gt;'  maxlength=10&gt;
  &lt;br&gt;&lt;font size=2 
  color=red&gt;&lt;%=formHandler.getErrorMsg("password1")%&gt;&lt;/font&gt;
  &lt;/td&gt;
  &lt;td  valign=top&gt;
  &lt;B&gt;Confirm Password&lt;sup&gt;*&lt;/sup&gt;&lt;/B&gt;
  &lt;br&gt;
  &lt;input type="password" name="password2" size=10 
  value='&lt;%=formHandler.getPassword2()%&gt;'  maxlength=10&gt;
  &lt;br&gt;&lt;font size=2 
  color=red&gt;&lt;%=formHandler.getErrorMsg("password2")%&gt;&lt;/font&gt;
  &lt;/td&gt;
  &lt;br&gt;
  &lt;/tr&gt;
  &lt;tr bgcolor="lightblue"&gt;
  &lt;td colspan=2 align=center&gt;
  &lt;input type="submit" value="Submit"&gt; 
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/center&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>FormBean.java</p>
  
  <pre><code>package test;
  
  import java.io.*;
  import java.util.*;
  
  public class FormBean {
        private String firstName;
        private String lastName;
        private String email;
        private String userName;
        private String password1;
        private String password2;
        private String zip;
        private String notify;
        private Hashtable errors;
        public boolean validate() {
          boolean bool=true;
          if (firstName.equals("")) {
            errors.put("firstName","Please enter your first name");
            firstName="";
            bool=false;
          }
          if (lastName.equals("")) {
            errors.put("lastName","Please enter your last name");
            lastName="";
            bool=false;
          }
          if (email.equals("") || (email.indexOf('@') == -1)) {
            errors.put("email","Please enter a valid email address");
            email="";
            bool=false;
          }
          if (userName.equals("")) {
            errors.put("userName","Please enter a username");
            userName="";
            bool=false;
          }
          if (password1.equals("") ) {
            errors.put("password1","Please enter a valid password");
            password1="";
            bool=false;
          }
          if (!password1.equals("") &amp;&amp; (password2.equals("") || 
              !password1.equals(password2))) {
            errors.put("password2","Please confirm your password");
            password2="";
            bool=false;
          }
          if (zip.equals("") || zip.length() !=9 ) {
            errors.put("zip","Please enter a valid cell number");
            zip="";
            bool=false;
          } else {
            try {
              int x = Integer.parseInt(zip);
            } catch (NumberFormatException e) {
              errors.put("zip","Please enter a valid cell number");
              zip="";
              bool=false;
            }
          }
          return bool;
        }
        public String getErrorMsg(String s) {
          String errorMsg =(String)errors.get(s.trim());
          return (errorMsg == null) ? "":errorMsg;
        }
        public FormBean() {
          firstName="";
          lastName="";
          email="";
          userName="";
          password1="";
          password2="";
          zip="";
          notify="";
          errors = new Hashtable();
        }
        public String getFirstName() {
          return firstName;
        }
        public String getLastName() {
          return lastName;
        }
        public String getEmail() {
          return email;
        }
        public String getUserName() {
          return userName;
        }
        public String getPassword1() {
          return password1;
        }
        public String getPassword2() {
          return password2;
        }
        public String getZip() {
          return zip;
        }
        public String getNotify() {
          return notify;
        }
        public void setFirstName(String fname) {
          firstName =fname;
        }
        public void setLastName(String lname) {
          lastName =lname;
        }
        public void setEmail(String eml) {
          email=eml;
        }
        public void setUserName(String u) {
          userName=u;
        }
        public void  setPassword1(String p1) {
          password1=p1;
        }
        public void  setPassword2(String p2) {
          password2=p2;
        }
        public void setZip(String z) {
          zip=z;
        }
        public void setErrors(String key, String msg) {
          errors.put(key,msg);
        }
        public void setNotify(String n) {
          notify=n;
        }
      }
  </code></pre>
  
  <p>Registration.java</p>
  
  <pre><code>package test;
  
  import java.io.*;
  import java.sql.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  public class Registration extends HttpServlet{
  /**
       * 
       */
      private static final long serialVersionUID = 1L;
  public void init(ServletConfig config) throws ServletException{
  super.init(config);
  }
  public void doPost(HttpServletRequest req, HttpServletResponse res) 
  throws ServletException, IOException{
  String connectionURL = "jdbc:mysql://localhost:3306/jsp";
  Connection connection=null;
  ResultSet rs;
  res.setContentType("text/html");
  PrintWriter out = res.getWriter();
  String firstNamed = req.getParameter("firstName");
  String lastNamed = req.getParameter("lastName");
  String emaild = req.getParameter("email");
  String userNamed = req.getParameter("userName");
  String password1d = req.getParameter("password1");
  String zipd = req.getParameter("zip");
  String auto = "u";
  try {
  Class.forName("org.gjt.mm.mysql.Driver");
  connection = DriverManager.getConnection(connectionURL, "root", "root"); 
  String sql = "insert into userprofile values (?,?,?,?,?,?,?)";
  PreparedStatement pst = connection.prepareStatement(sql);
  pst.setString(1, firstNamed);
  pst.setString(2, lastNamed);
  pst.setString(3, emaild);
  pst.setString(4,userNamed);
  pst.setString(5, password1d);
  pst.setString(6, zipd);
  pst.setString(7, auto);
  
  int numRowsChanged = pst.executeUpdate();
  out.println(" Welcome : ");
  out.println(" '"+userNamed+"'");
  pst.close();
  }
  catch(ClassNotFoundException e){
  out.println("Couldn't load database driver: " + e.getMessage());
  }
  catch(SQLException e){
  out.println("SQLException caught: " + e.getMessage());
  }
  catch (Exception e){
  out.println(e);
  }
  finally {
  
  try {
  if (connection != null) connection.close();
  }
  catch (SQLException ignored){
  out.println(ignored);
  }
  }
  }
  }
  </code></pre>
  
  <p>Briefly: ragister.html -> proces.jsp, if all info valid -> Registration.java with sending data to db, else retry.jsp with error description till everything is ok.
  It seems to work preety fine, but in database i get a table with row filled with nulls :(</p>
  
  <p>Probably i made mistake trying to read data in Registration.java.
  Please, please help me and sory if i am unclear anywhere. </p>