• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp Login

 
Reuben Fields
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

im tryin to get a login working in jsp but it doesnt seem to be accessing the while loop...

any ideas on how i can get this working?

<%

Class.forName("org.gjt.mm.mysql.Driver");
String strUrl = "jdbc:mysql://localhost/broadweb";
Connection conn=DriverManager.getConnection (strUrl,"root","321321");

Statement stmt=conn.createStatement();

// Get Parameters
String login_name = request.getParameter("login_name");
String password = request.getParameter("password");

// Query String
String strSQL = "SELECT person_type FROM person WHERE login_name = '" + login_name + "' AND password = '" + password + "'";

// Execute
ResultSet result = stmt.executeQuery(strSQL);
while (result.next())
{
String person_type = result.getString(1);
if (person_type.equals("member"))
{
HttpSession currSession = request.getSession(true);
currSession.putValue("priv", "1");
//String storedName = currSession.getValue("userName");

out.print("Member\n\n");
}
else if (person_type.equals("admin"))
{
HttpSession currSession = request.getSession(true);
currSession.putValue("priv", "2");

out.print("Administrator\n\n");
}
else
{
out.print("Error - Invalid Type\n\n");
}

}

// Close
stmt.close();
conn.close();

%>
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im tryin to get a login working in jsp but it doesnt seem to be accessing the while loop...


It probably means your query

did not return any matches.

I would verify that the login/password exists in your table.
 
Reuben Fields
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah i have the info in my database so i dont know why its not working
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does the query result on sql console if yes then

<%=strSQL %> what is out put of this ? and did you try printing the query on jsp and executing same.

what if login_name or password is null ???

Shailesh
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally, cannot see anything wrong with the syntax of your code. So assuming you are not getting any errors, I would again suggest you verify that the data values are correct.

Have you verified that the following is returning valid data and the syntax of the url is correct:
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and one more thing. If you are not sending the login_name and password values as part of the url, which is something I recommend.

And if you are using the "POST" method(for example a Form submit) to forward the data in the request object, you will need to access your data by using the following getAttribute methods of the SerlvetRequest Interface instead of the getParameter methods:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic