title: Basic Java Login Servlet Not working
body: <p>I have created a msacess db <strong>mydb.accdb</strong> and pointed the odbc source to it and i have the following code in the lserv.java file all the necesary config for tomcat had been done and the servlet had no response so i added a print error in the init method which showed up the following error </p>
  
  <pre><code>javax.servlet.ServletException: Servlet.init() for servlet login threw exception
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
      org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
      org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
      java.lang.Thread.run(Thread.java:722)
  root cause
  
  java.lang.NullPointerException
      lserv.init(lserv.java:23)
      javax.servlet.GenericServlet.init(GenericServlet.java:212)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
      org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
      org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
      java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>The java code </p>
  
  <pre><code>import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  
  public class lserv extends HttpServlet
  {
  Connection con;
  ResultSet rs;
  Statement st;
  PrintWriter out;
  public void init() 
  {
  try
  {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  con=DriverManager.getConnection("jdbc:odbc:mydb");
  st=con.createStatement();
  
  }
  catch(Exception e)
  {
  out.println(e.getMessage());
  }
  }
  
  public void doGet(HttpServletRequest req,HttpServletResponse res) 
  {
  
  try
  {
  out=res.getWriter();
  res.setContentType("text/html");
  if(req.getParameter("sub").equals("value"))
  {
  String s1=req.getParameter("t1");
  String s2=req.getParameter("t2");
  rs=st.executeQuery("SELECT * FROM login WHERE uname='"+s1.trim()+"AND pass='"+s2.trim()+"';" );
  if(rs.next())
  {
  out.println("welcome");
  }
  else
  {
  out.println("sorry");
  }
  
  }
  }
  catch(Exception e){
  out.println(e.getMessage());
  }
  }
  }
  </code></pre>
  
  <p>The html page code </p>
  
  <pre><code>&lt;html&gt;
  &lt;title&gt;Login System&lt;/title&gt;
  &lt;style type="text/css"&gt;
  div.ex {
  width:220px;
  padding:10px;
  border:5px solid gray;
  margin:10px;
  }
  &lt;/style&gt;
  
  &lt;body&gt;
  &lt;div class="ex"&gt;
  &lt;strong&gt;User Login&lt;/strong&gt;
  &lt;form name=f1 method=get action="http://localhost:8080/login"&gt;
  User &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&lt;input type=text name=t1&gt;&lt;br&gt;
  Password &lt;input type=password name=t2&gt;&lt;br&gt;
  &lt;input type=submit name=sub value="Login"&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have a table named login with field uname and pass with values.</p>
  
  <p>What is the problem?Please help</p>