aspose file tools*
The moose likes Struts and the fly likes Checking username Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Checking username" Watch "Checking username" New topic
Author

Checking username

leo oke
Greenhorn

Joined: Jul 09, 2007
Posts: 21
I want to do this, When the user input is processed, it will be checked against the database to see what�s 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 width="100%" 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;
}

}

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest creating a JavaBean named "User" containing a userId and a role property. When the user logs on, query the database for that user ID. If the password matches, retrieve the role and place it in the User bean. Then place the User bean in the HTTPSession object using the setAttribute Method. In the welcome JSP, you can then get the user role with the following statement:


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking username
 
Similar Threads
form Authentication
iterate problem in struts2
When Validation Error I Lose My Bean Value-Struts 2
connecting struts with database
blank page - Action is not called