Friday, 19 December 2008

Hints for a complete STRUTS Application (1)

Source code is available from arsaral(at) Hint: Running a program at the very beginning of a STRUTS application.

It is necessary to prepare the working environment before the standard STRUTS application begins to function through its menus and screens. Opening databases, some logging etc. may be done using this approach. Please note, I do not refer to authentication at this point. Some of these tasks may be done before the authentication or after it, depending on the implementation.


<forward path="/" name="init">

<action path="/init" name="init" type="com.actions.InitAction">
<forward path="/mainmenu.jsp" name="start">

Here, mainmenu.jsp is a jsp file residing in the WEB-INF directory. This can be any jsp which may be used
for the main menu navigation of the STRUTS application.

In the src folder of the application, there is a com and in that there is an actions folder where resides:

InitAction source follows:

package com.actions;

import javax.servlet.http.*;
import org.apache.struts.action.*;

public class InitAction extends Action {

// The constructor method for this class
public InitAction() {

// This sets the list as a session bean
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

// Any code to prepare the environment for the new born application goes here…

ActionForward forward = mapping.findForward("start");
return forward;

As seen above, the “start” ActionForward keyword trigs the execution of the mainmenu.jsp in the