I've got a
struts database that I want to forward the success database result to a
jsp page.
I've built the logic class and the interface to connect to the database ,but the action class has the problem.
I want to pass the userList from the logic class into the action class then forward it to the jsp page!
I tried this code but get an error..How is it done ? any help
part code
logic class
// Creates a new instance of MysqlUserDAO
public MySqlUserDAO(Connection myConnection){
this.myConnection = myConnection;
}
public ArrayList getUser(LoginForm form) {
ArrayList userList = new ArrayList();
try {
String query = "SELECT * FROM `role` NATURAL JOIN `user` WHERE username = '"+form.getName() +"' ";
Statement stmt = myConnection.createStatement();
ResultSet rs =stmt.executeQuery(query);
// extract data from the ResultSet
while(rs.next()){
// /** Here we put role into the userist: */
String role = rs.getString("role");
userList.add(rs.getString("role"));
.........................
return userList;
.............................
interface class
public interface UserDAO {
public ArrayList getUser(LoginForm form);
}
part code
action class
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpSession session = request.getSession();
//get connection from database
javax.sql.DataSource dataSource;
java.sql.Connection myConnection = null;
// Here the method that connects to the datasource is called:
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
UserDAO dao = DAOFactory.createUserDAO(myConnection);
//Below code is the part which I have the problem ,I want to pass the userList from the logic class
------> userList = dao.getUser(LoginForm form); <--------- this is where the problem lays. Its not correct ,there must be away bring the userList to the action class?