File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Checking username

leo oke

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">
<td colspan="2">

<td width="15%">Enter your name:</td>
<td width="85%">
<html:text property="name" size="25" maxlength="50"

Formbean code

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

private String name = null;

private String result ;

public void setName(String 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:

Consultant, Sima Solutions
I agree. Here's the link:
subject: Checking username
It's not a secret anymore!