title: I have a problem of null pointer Exception in servlet
body: <p>HI, all</p>
  
  <p>I have a problem of null pointer Exception in servlet .
  I have a form a.jsp with check box if I do not select this check box and submit form then null pointer exception is occur in a.servlet.
  How I Can handle this Exception</p>
  
  <p>code 
  a.jsp</p>
  
  <pre><code>&lt;table border='0' width='50%' cellspacing='0' cellpadding='0' &gt;&lt;form name=form1 method=post action=aservlet &gt;
  &lt;input type=hidden name=todo value=post&gt;
  
  &lt;tr bgcolor='#ffffff'&gt;&lt;td align=center &gt;
  &lt;font face='verdana' size='2'&gt;&lt;b&gt;Sex&lt;/b&gt;&lt;input type=radio name=sex value='male'&gt;Male &lt;/font&gt;
  &lt;input type=radio name=sex value='female'&gt;&lt;font face='verdana' size='2'&gt;Female&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;&lt;td align=center bgcolor='#f1f1f1'&gt;
  &lt;font face='verdana' size='2'&gt;&lt;input type=checkbox name=agree &gt;I agree to terms and conditions &lt;/font&gt;
  &lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr bgcolor='#ffffff'&gt;&lt;td align=center &gt;
  &lt;input type=submit value=Submit&gt;
   &lt;input type=reset value=Reset&gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;/form&gt;&lt;/table&gt;
  </code></pre>
  
  <p>aservlet.java</p>
  
  <pre><code>import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  
  public class Admin extends HttpServlet {
          public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException 
              {
              response.setContentType("text/html");
              PrintWriter out = response.getWriter();
  request.getParameter ("agree");
  }}
  </code></pre>
  
  <p>Exception:</p>
  
  <p>exception </p>
  
  <p>java.lang.NullPointerException
      com.centralvisa.servlets.Admin.doPost(Admin.java:26)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)</p>
  
  <p>Thanks</p>