Hey guys i am making a small project based on JSP and Servlet. Everything is OK..but when i run the below mentioned code of an JSP page and servlet...i am getting an exeption named "java.lang.NullPointerException".
There are no errors in my pages..but still i am getting this exeption.
So can anyone PLEASE help me regarding this.
Thanx.
index.jsp:-
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Login Form </title>
</head>
<form action="Login" method="post"/>
<body>
<br>
<br>
<center><h3> Please fill in the following information in order to continue with your registration</h3></center>
<br>
<br>
<table border="2" bordercolor="black" align="center" cellpadding="5" cellspacing="2" width="450" height="300">
<tr>
<td ><center><font color="black"><b>First Name </b></font></center></td>
<td><center><input type="text" name="fn"></center></td>
</tr>
<tr>
<td><center><font color="black"><b>Last Name</b></font></center></td>
<td><center><input type="text" name="ln"></center></td>
</tr>
<tr>
<td><center><font color="black"><b>Address</b></font></center></td>
<td><center><input type="text" name="address"></center></td>
</tr>
<tr>
<td><center><font color="black"><b>Contact Number</b></font></center></td>
<td><center><input type="text" name="cno"></center></td>
</tr>
<tr>
<td><center><font color="black"><b>E-Mail ID</b></font></center></td>
<td><center><input type="text" name="EMail"></center></td>
</tr>
<tr>
<td><center><font color="black"><b>Registration Date</b></font></center></td>
<td><center><input type="text" name="Rd"/></center></td>
</tr>
</table>
</body>
<br>
<br>
<center><input type="submit" value=" Save "> <input type="reset" value=" Reset " onclick="location.reload()"></center>
</html>
Login.java(servlet):-
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.*;
public class Login extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String fn =request.getParameter("First Name");
String ln =request.getParameter("Last Name");
String address=request.getParameter("Address");
String cno=request.getParameter("cno");
String EMail=request.getParameter("E-Maild ID");
String Rd=request.getParameter("Registration Date");
try
{
if(fn.length()==0 && ln.length()==0 && address.length()==0 && cno.length()==0 && EMail.length()==0 && Rd.length()==0)
{
response.sendRedirect("error.html");
}
else
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:Family","","");
PreparedStatement ps = c.prepareStatement("insert into Friends values (FirstName,LastName,Address,ContactNo,EMailID,RegistrationDate) values(?,?,?,?,?,?)");
ps.setString(1, fn);
ps.setString(2, ln);
ps.setString(3, address);
ps.setString(4, cno);
ps.setString(5, EMail);
ps.setString(6, Rd);
ps.executeUpdate();
response.sendRedirect("success.html");
}
}
catch(Exception ec)
{
out.print(ec);
}
finally {
out.close();
}
}
@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";
}
}