The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

need help getting started

Hello. I am a long time programmer in C++ who has had some experience with Java in the past, but almost exclusively simple, good old fashioned stuff, with no databases or web servers or anything like that.

Now, I need to learn how to write servlets, both for my own uses (a personal project I'm working on) but also to show a potential employer that I know how. Because this is also for a potential employer, I am using their tool chain. I have no problem learning from tutorials and the like, so this is also no big issue. The problem is I can't seem to get the silly environment configured, and all the tutorials I've went through just take for granted certain steps.

I am using Eclipse, Tomcat, and postgres. If anyone could please post a step by step set of instructions to get all three of these things working together, that would be great. I've gotten Eclipse and postgres talking and have worked through several turorials there, and I have also gotten Eclipse and Tomcat working together, and don some tutorials in that direction. The problem is making all three work together.

Any help anyone can offer would be greatly appreciated. I am at my wits end after 3 days of struggling with this, and I am about to toss the whole thing out the window.

Re: need help getting started

Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

It seems you're well past getting started. Phew!

Please post the code you've tried to connect all 3 elements of your development environment, and provide any errors or descriptions of other evidence you're seeing that indicate the code is not achieving the desired result.

Re: need help getting started

Originally Posted by GregBrannon

Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

It seems you're well past getting started. Phew!

Please post the code you've tried to connect all 3 elements of your development environment, and provide any errors or descriptions of other evidence you're seeing that indicate the code is not achieving the desired result.

Re: need help getting started

Upon viewing the error from tomcat more closely, I don't think my original thought was correct. It looks more like the LoginServlet did not get called (or found?) correctly when called from the LoginPage. This may have nothing to do with db access at all. If so, sorry.

Edit: After doing a little more digging, I'm beginning to think that it may have something to do with the web.xml file, but I really don't understand what this file does or what I might need to do to fix it. This is my web.xml file:

Re: need help getting started

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 )

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.

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.