Ok, got the silly errors out of the way, and I am back to the issue that brought me here originally. It was a problem with my web.xml file. This is the correct one, in case anyone is trying this on their own. I was basically missing the package name in the class definition (oops... silly me
)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>LoginExample</display-name>
<welcome-file-list>
<welcome-file>LoginPage.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>ExamplePackage.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
</web-app>
Now, when I run the program, it seems to do its thing, but it tells me i do not exist in the db, even when I do. Its definitely passing the info into the right classes, etc, because in my console in Eclipse I am getting this output:
Your user name is eternal_sage
Your password is Pass1234
Query: select * from users where username='eternal_sage' AND password='Pass1234';
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
Log In failed: An Exception has occurred! java.lang.NullPointerException
which is consistent with the error checking in the UserDAO class. I know the statement generated by the code works, as I've copied it verbatim into psql in the terminal and it gets exactly the result I'm looking for. What I am not understanding is the class not found exception. What does this mean? Am I missing some include or a lib or something? I am not sure I understand this statement in the source code either (its copied from a tutorial, not my own). What purpose does it serve? Is it just error checking? More digging, I suppose.
Oh, and sorry for posting and editing so much. I guess this thread is the equivalent of me thinking out loud so far. If this is somehow disrespectful, please just delete the thread. I just can't wait until someone answers to keep hacking at this thing, and as I am figuring out my screw ups it seems important to keep the thread updated so if someone does try to help me they have full info. I know you guys are busy, don't misunderstand. Its just that I have the time to work on this today, and may not for a while. Besides, I learn better when I figure it out on my own
sometimes I just need a nudge in the right direction.
--- Update ---
Ok. Seems that the tutorial I was following was using the ODBC to try and connect to the DB, which from my understanding, is a terrible, outdated, and not cross-platform compatible method of doing things. So I replaced all that code with the code I used in my DB program that I know works (using the JDBC postgres driver) and registered the silly thing in the classpath (oops) and viola, I'm to a whole new error
. Looking at my console, it seems that I have actually accessed the db now, it seems to be an issue with the UserLogged.jsp which is the destination page when the db access is successful. This error seems to have something to do with the UserBean class, or at least how it is being used in this case.
UserLogged:
<%@ page language="java"
contentType="text/html; charset=windows-1256"
pageEncoding="windows-1256"
import="ExamplePackage.UserBean"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=windows-1256">
<title> User Logged Successfully </title>
</head>
<body>
<center>
<% UserBean currentUser = (UserBean(session.getAttribute("currentSessionUser")));%>
Welcome <%= currentUser.getFirstName() + " " + currentUser.getLastName() %>
</center>
</body>
</html>
The error is pointing at the line UserBean currentUser = (UserBean(session.getAttribute("currentSessionUser ")));
which looks alittle weird to me as well, although I'm not sure exactly what its doing, so I'm going to keep digging.
Edit: N/M I realized I needed to cast the UserBean. The code should have looked like this: <% UserBean currentUser = ((UserBean) (session.getAttribute("currentSessionUser")));%>
Which means that I am up and running completely! WOOT! I'll mark this as solved then. Sorry for all the trouble. Maybe my ramblings will help someone else, though.