File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts Controller to Controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Controller to Controller" Watch "Struts Controller to Controller" New topic

Struts Controller to Controller

Suresh Kumar Ramasamy

Joined: Mar 18, 2008
Posts: 7

Design one action servlet for each jsp - All actions emanating from a JSP should be handled by the corresponding servlet.


Assume that one.jsp on click of a button has to go to two.jsp. This two.jsp needs some values (say for populating a combo) before loading.

Possible Solution without considering the Constraint:

Invoke two.jsp from one.jsp (View to View). Call a function in the header of two.jsp which will submit the form to for retrieval of the values (Hope this will work).

What I have done:

one.jsp submits the form to has the following code:
return new two().execute(mapping,form,request,response); has nothing special. After retrieving the required values, the execute method issues mapping.findForward(forwardName);

The struts config file has an entry for for the forward name set by to navigate to two.jsp.


Is this a standard way? If not, what are the better ways?

Thanks & Regards.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Suresh Kumar Ramasamy:

Is this a standard way?

No, it's not. There are several problems with it. The main one is that the execute method in is expecting the mapping and form objects to be those defined for the two action. Instead, in this case they are the mapping and form for the one action.

Originally posted by Suresh Kumar Ramasamy:
If not, what are the better ways?

Yes, there are better ways. Here are two possibilities:

Method 1: Refactor the code that prepares for two into a method in a Controller Helper or Controller Utility class. Example: ControllerUtils.prepareTwo(). You can then call this method from either the one or two actions.

Method 2: Create both a preparatory and an execution action for each page. Then create a forward for the page one execution action that forwards to the preparatory action for page two. Example:

[ March 18, 2008: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I generally use "Method 2".

- Brent
I agree. Here's the link:
subject: Struts Controller to Controller
It's not a secret anymore!