This is login Filter in servlet.
import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.sql.*;
public class Filt implements Filter
{
FilterConfig fcg;
public void init(FilterConfig f)
{
fcg=f;
}
public void doFilter(ServletRequest req,ServletResponse res,FilterChain ch)throws IOException,ServletException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
try
{
String name=req.getParameter("name");
String pass=req.getParameter("pass");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","navjyoti","jyoti7");
PreparedStatement pst=con.prepareStatement("select * from employee where password=?");
pst.setString(1,pass);
ResultSet rs=pst.executeQuery();
if(rs.next())
{
//out.println("welcome:'"+name+"'");
//RequestDispatcher rd=req.getRequestDispatcher("login.do");
//rd.include(req,res);
ch.doFilter(req,res);
}
else
{
out.println("invalid username&password"+name);
RequestDispatcher rd=req.getRequestDispatcher("index.html");
rd.include(req,res);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void destroy()
{
}
}