Hi, i have a servlet program..to verify the login and redirect to correct html page on verification. public class LoginServlet extends HttpServlet implements javax.servlet.Servlet {
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
// Get the requested name and the output writer.
PrintWriter out = response.getWriter ();
String username = request.getParameter("UserName");
String password = request.getParameter("Password");
//Used to instantiate a connection
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "rapax";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password1 = "ajay12";
Statement stmt = null;
ResultSet rs = null;
try
{
try
{
Class.forName(driver).newInstance();
}
catch(InstantiationException e)
{
}
catch(IllegalAccessException e)
{
}
con = DriverManager.getConnection((new
StringBuilder()).append(url).append(dbName).toString(),userName,password1); System.out.println("Connected to the database"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM login where
username="+username+" and password="+password); // displaying records if(rs.next()) { String uname=rs.getObject(1).toString(); String pwd=rs.getObject(2).toString();
response.sendRedirect("http://localhost:8080/sessionAction.html");
}
else
{
out.println("\n\nInvalid Login\n");
rs.close();
response.sendRedirect("http://localhost:8080/login.html");
}
// throw new IOException(new IOException("Error"));
}
catch (SQLException e)
{
}
catch (ClassNotFoundException e) {
}
finally
{
try
{
if(rs!=null)
{
try{
rs.close();
}
catch(NullPointerException e)
{
}
}
rs = null;
if(stmt!=null)
{
try
{
stmt.close();
}
catch(SQLException e)
{
}
}
stmt = null;
if(con!=null)
{
try
{
con.close();
}
catch(NullPointerException e)
{
}
}
con = null;
}
catch (SQLException e)
{
}
out.close();
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
doPost(request,response);
}
}
.i am unable to redirect..here is the code..pls help me THANK YOU
Please visit the following link: