I think why you would want to do it is pretty obvious, you need to get data from the database to display on your page, such as a list of items. A better question is why would you not want to. That answer to that question is that it would be better to encapsulate your database query in a Data Access Object(DAO) and have your action call the DAO. Here is a sample of the execute method for doing it with the DAO:

private ItemDAO dao = DAOFactory.getItemDAO();

public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
        throws Exception {

    request.setAttribute("items",dao.getItems());
    return mapping.findForward("list");

}

The idea would be that ItemDAO is an interface and the getItems method returns a collection of items. You would write an implementation of the ItemDAO where the getItems method does the database query. DAOFactory.getItemDAO() is a static method that returns an instance of an object that implements the ItemDAO interface.

As your application gets more complicated, you may want to have the action call a service, which in turn calls the dao, but if your page is pretty simple, that step probably won't be needed.


Peng Tuck Kwok wrote:

On Fri, 30 Jul 2004 09:07:36 -0400, Bussie, Andre D
<[EMAIL PROTECTED]> wrote:

Is there a way in the Jakarta Struts framework to perform a database
query in an Action class w/o using a Action Form Class?


It sure is. The next question would be: why would you want to do that in the action ? :D

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to