Need serious help with JSP + JDBC/Database connection
843835Apr 3 2003 — edited Apr 8 2003Hey all,
I have to build an assignment using JSP pages. I am still pretty new and only learning through trial and error. I understand a bit now, and I have managed to get a bit done for it.
I am having the most trouble with a Login Screen. The requirements are that the a form in a webpage has Username/Number and Password, the user clicks Login, and thats about it. The values for the username/number and password NEED to come from the database and I cannot manage to do this. The thing I have done is basically hardcode the values into the SQL statement in the .jsp file. This works, but only for that one user.
I need it so it checks the username/number and password entered by the user, checks the database to see if they are in it, and if so, give access. I seriously am stuck and have no idea on what to do.
I dont even know if I have made these JSP pages correct for starters, I can send them out if someone is willing to look/help.
I have setup 3 other forms required for the assignment and they are reading data from the db and displaying within tables, I need to do this with non-hardcoded values aswell. Im pretty sure I need to use for example 'SELECT .... FROM .... WHERE username= +usrnm' (a variable instead of username="john" , this is hardcoded), I just CANNOT figure out how to go about it.
Its hard to explain through here so I hope I gave enough info. A friend of mine gave some psuedocode i should use to make it, it seems ok to follow, its just I do not know enough to do it. He suggested:
get the username and pass from the env vars
open the db
make an sql (eg SELECT user, pass FROM users WHERE user = envuser)
index.jsp points to login.jsp
login.jsp get the vars you put into index.jsp
opened the db
is the query returns nothing - then the user is wrong
OR if the passwords dont match
- redirect back to index.jsp
if it does match
- set up a session
- redirect to mainmenu.jsp
Anyway, thanks for any help you can give.
-Aaron