|
Re: Servlet Query!
|
Posted: Nov 3, 2005 10:52 PM
|
|
Indent your code and eclose it in the Java Tags so we can actually read it...
> Hi.. > I am new to servlets . My first program executed.. > but the second one is having problem as all is going right > but when i submit the uid and pwd through the html i get a > blank page.it shows nothing. > > > Servlet Code: > import java.io.*; > import javax.servlet.*; > import javax.servlet.http.*; > import java.sql.*; > > > public class login extends HttpServlet > { > public void doGet(HttpServletRequest > req,HttpServletResponse res) throws > ServletException,IOException > { > String uid=req.getParameter("t1"); > String pwd=req.getParameter("t2"); > > PrintWriter out=res.getWriter(); > > res.setContentType("text/html"); > > try > { > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); > Connection con=DriverManager.getConnection("jdbc : > odbc:ms","scott","tiger"); >
Ensure the name of the column is correct, i.e. your table must have the columns uid1 and pwd as defined in your select statement. > PreparedStatement psm=con.prepareStatement("select * from > reg where uid1=? and pwd=?");
> psm.setString(1,uid); > psm.setString(1,pwd);
// because it replaces question mark 1 in the select
// statment above.
psm.setString(1, uid);
// because it replaces question mark 2 in the select
// statemtnt
psm.setString(2, pwd);
The rest seems OK, run those changes they should work if everything mentioned has been satisfied else get back here, and we'll try to figure it out. Also if you are running a test on a mozilla-based browser you may print out the errors it gives to the Java Console under the menu option Tools. If you post that error on the forum it will help us determine what the beef is with your web-app.
> ResultSet rs=psm.executeQuery(); > if(rs.next()) > { > out.println("<html><head><title>WELCOME</title></hea d>"); > out.println("<body><b><i>Hello user "+uid+"</b></i>"); > out.println("</body></html>"); > } > else > res.sendRedirect("http://localhost:8080/login.html"); > } > catch(Exception e) > { > e.printStackTrace();} > } > } > > plz help me out ... > thanks .
|
|