// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package test;

import java.io.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.struts.action.*;

public class ListAction extends Action {
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws IOException, ServletException {
        if(request.getSession().getAttribute("user") == null) {
            return mapping.findForward("not.logged.in");
        }
        try {
            request.setAttribute("all", StrutsUsers.getInstance().getAll());;
            return mapping.findForward("data.ok");
        } catch (ClassNotFoundException ex) {
            ActionErrors errors = new ActionErrors();
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("database.error"));
            saveErrors(request, errors);
            return mapping.findForward("data.error");
        } catch (SQLException ex) {
            ActionErrors errors = new ActionErrors();
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("database.error"));
            saveErrors(request, errors);
            return mapping.findForward("data.error");
        }
    }
}
