Hi everyone,
I have been stalling on my servlet for over a week now and am unsure what the
problem is. When i submit the login information, I receive a blank page. I am
using MS Access to store the login information. No matter what data I put in
(correct or incorrect) I still receive a blank page. Infact I don't think im
even getting to the login validation stage. If the login is correct, it should
load the ("WTSTopSecret") servlet. I have got this to work with one inputfield
("name"), however, not with name and password. I would appreciate any help on
this.
The code is:
--------WTSLogin.java---------
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class WTSLogin extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><body>");
out.println("<form METHOD=POST ACTION=WTSLogin>");
out.println("Enter your User ID: ");
out.println("<INPUT TYPE=text name=userid><br>");
out.println("Enter your Password: ");
out.println("<INPUT TYPE=password name=password><br>");
out.println("<INPUT TYPE=submit value=Enter>");
out.println("</form></body></html>");
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String name = "";
String number = "";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String[] username = req.getParameterValues("name");
String[] passwd = req.getParameterValues("password");
if ((username != null) && (passwd != null))
{
String userid = username[0];
String pin = passwd[0];
if ((userid.length() > 0) && (pin.length() > 0))
{
name = userid;
number = pin;
}
try
{
// Load the jdbcodbc driver (and register it)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Get a Connection to the database
con = DriverManager.getConnection("jdbc:odbc:LoginServlet");
// Create a statement object
stmt = con.createStatement();
// Execute an SQL query
// rs = stmt.executeQuery("Select * from Logins where Name = '" +
name + "'");
rs = stmt.executeQuery("SELECT * from Logins WHERE (Name = '" + name +
"' AND Number = '" + number + "') ;");
// Display the results
if (rs.next())
{
HttpSession session = req.getSession(true);
session.setAttribute("loggedin", name);
res.sendRedirect("WTSTopSecret");
return;
}
else
{
res.sendRedirect("http://localhost:8080/sorry.html");
}
}
catch(ClassNotFoundException e)
{
out.println("Couldn't load the database driver: " + e.getMessage());
}
catch(SQLException e)
{
out.println("SQLException caught: " + e.getMessage());
}
}
}
}
------------------------
Any private emails welcome.
Im very grateful to you all.
Thanks,
Dharmesh
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html