1/ Please note that you put a ";" at the end of your second Sql query ...
2/ Try to replace "res.sendRedirect("WTSTopSecret");" by
"res.sendRedirect("http://www.google.com");"
to verify that your alias "WTSTopSecret" is well mapped.
3/ In all cases, don't forget to close your ResultSet and Statement objects,
in a "finally" clause for example ... Be careful too of what you will do
with
your database Connection ...
Hope it can helps you ...
L.C.
-----Message d'origine-----
De : A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]De la part de
Dharmesh Patel2
Envoy� : mardi 26 mars 2002 12:11
� : [EMAIL PROTECTED]
Objet : Problem with my Login servlet
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
___________________________________________________________________________
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