Could you please help me do the last lines that has ??? :
now I have the employees table and the roles table , I created the Employee javabean, in the LoginAction when the emploee login I put :
session.setAttribute("USER", username);
..
return (mapping.findForward(target)); this target is another Action called : EmployeeCustomizedAction :
public class EmployeeCustomizedAction extends Action {
protected ArrayList getEmployees(HttpServletRequest request) {
Employee employee = null;
ArrayList employees = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource)
context.getAttribute(Action.DATA_SOURCE_KEY);
// get the username from session
HttpSession session = request.getSeesion();
String user = session.getAttribute("USER");
try {
conn = dataSource.getConnection();
stmt = conn.createStatement();
rs =
stmt.executeQuery("select * from employees, roles, "
+ "where employees.roleid=roles.roleid "
+ "and employees.username=user");
while ( rs.next() ) {
employee = new Employee();
employee.setUsername(rs.getString("username"));
employee.setName(rs.getString("name"));
employee.setRolename(rs.getString("rolename"));
employee.setPhone(rs.getString("phone"));
employee.setEmail(rs.getString("email"));
employee.setRoleid(new Integer(rs.getInt("roleid")));
employee.setDepid(new Integer(rs.getInt("depid")));
employee.setDepartment(rs.getString("depname"));
employees.add(employee);
System.err.println("Username : "
+ employee.getUsername()
+ " Department : " + rs.getString("depname"));
}
}
catch (SQLException e) {
System.err.println(e.getMessage());
}
finally {
if (rs != null) {
try {
rs.close();
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
stmt = null;
}
if (conn != null) {
try {
conn.close();
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
conn = null;
}
}
return employees;
}
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
Employee employee = null;
// Default target to success
String target = new String("success");
ArrayList employees = null;
employees = getEmployees(request);
// Set the target to failure
if ( employees == null ) {
target = new String("login");
}
else {
request.setAttribute("employees", employees);
if (rolename is = doctor HOW TO DO THIS ???)
target = new String("doctor");
if (rolename is = nurse HOW TO DO THIS ???)
target = new String("nurse");
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}
[ April 03, 2006: Message edited by: majid nakit ]