Checking username against a database

I want to do this, When the user input is processed, it will be checked against the database to see whats the role associated with the user. If the user is in the admin role, it will show Hello Admin on the second page.

Using struts and mysql, I've got the jsp,Formbean ,but the mysql logic is problem .What's the solution on the sql side to check the user?

part code

<html:form action="/login">

<table border="0" cellspacing="2" cellpadding="0">

<tr>

<td colspan="2">

</td>

</tr>

<tr>

<td width="15%">Enter your name:</td>

<td width="85%">

<html:text property="name" size="25" maxlength="50"

onfocus="this.select()"/>

</td>

</tr>

Formbean code

public class LoginForm extends org.apache.struts.validator.ValidatorForm{

private String name = null;

private String result ;

public void setName(String name) {

this.name = name;

}

public String getName() {

return name;

}

public void setResult(String result) {

this.result = result;

}

public String getResult() {

return result;

}

}

Message was edited by:

suse69

[1272 byte] By [suse69a] at [2007-11-27 10:12:32]
# 1

Some suggestions:

Your user should not provide 'name' on the login page. He should provide 'userID' and 'password'. You check his userID and password in the database table to see if he is an authorized user. If so, you use his userID to look up his role in another database table.

Your project should have a clean separation of concerns between the presentation layer, business logic layer, and persistance layer. Ie, Model View Controller (MVC). You shouldn't see a database term such as resultSet in the layer that contains Struts.

Your persistance layer will query the database using a connection pool and return the data to the business logic layer as some type of collection such as String[], the busiess logic layer should not use a raw resultSet as you use in your example code (getResultSet, setResultSet).

I think it would be best to read a book on Struts and research good MVC design. There are good books on Struts such as 'Struts in Action'.

Also, you may want to read up on creating a peristance layer (using JDBC and not ORM) independent of Struts, the presentation and business logic layers.

From what I recall of Struts, the ValidatorForm is for validating the user's input on the web page only and not performing business logic such as looking up information in the database. There shouldn't be a resultSet there.

George123a at 2007-7-28 15:20:53 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...