
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.sql.*;
public class Login extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException , IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String name=req.getParameter("username:");
String pass=req.getParameter("password");
//boolean t=req.getValue("checkbox");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("Jdbc:Odbc:mydsn");
Statement s =c.createStatement();
ResultSet rs=s.executeQuery("select * from emp ");
if(rs.next())
{
if(name!=rs.getString(1)||pass!=rs.getString(2))
{
out.println("<html><body>");
int x =s.executeUpdate("insert in to emp values("+name+"),("+pass+") ");
out.println("u hv registered");
out.println("<a href=welcome.htm>next</a>");
out.println("</body></html>");
}
if(name==rs.getString(1)&&pass==rs.getString(2))
{out.println("<html><body>");
out.println("<a href=wecome.htm>login</a>");
out.println("</body></html>");}
/*if(t==true)
{
Cookie c1 =new Cookie("name","ducat");
Cookie c2 =new Cookie("add","noida");
res.addCookie(c1);
res.addCookie(c2);
c1.setMaxAge(30*60);
c2.setMaxAge(30*60);
}
*/
}
}
catch(Exception e){}
}}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.