This is servlets code,
package javacode;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class LoginAction extends HttpServlet {
private Connection con;
String url = "jdbc:
mysql://192.168.10.211:3306/";
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
public void init()throws ServletException {
System.out.println("INIT");
try {
Class.forName(driver);
con=DriverManager.getConnection(url+db,userName,password);
}//try
catch(Exception e){
e.printStackTrace();
throw new ServletException("unable to get database cooenction.");
}//catch
}//init
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException {
System.out.println("in service");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
PreparedStatement ps=null;
try{
String userid=req.getParameter("userid");
String pass=req.getParameter("password");
if(userid==null||userid.equals("")||pass==null||pass.equals("")){
out.println("<html><body>");
out.println("<i>UserName/Password are empty,they cannot be empty </i>");
out.println("</body></html>");
return;
}//if
ps=con.prepareStatement("select * from login where userid=? and password=?");
ps.setString(1,userid);
ps.setString(2,pass);
ResultSet rs=ps.executeQuery();
out.println("<html><body>");
if(rs.next())
out.println("Successfully login");
else
out.println("username and password not currect, please try again.");
out.println("</body></html>");
}//try
catch(Exception e){
out.println("unable to process the request please try later");
}//catch
finally {
try{
ps.close();
}
catch(Exception e) {}
}//finally
}//doget
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
doGet(req, res);
}
public void destroy() {
System.out.println("In destroy");
try {
con.close();
}
catch(Exception e) {
System.out.println(e);
}
}//destroy
}
------------------------------------------------
Read for more information.
http://www.roseindia.net/servletsThanks