I would like to render the same JSP for multiple Struts Actions. I'm having trouble because when rendering the JSP, the bean name is different depending on which Action was called. So, I can't call something like:
<c:out value="${myBean.myProperty}" />
because the bean isn't necessarily called myBean.
Currently, I've been getting around this by placing any common objects I'll need in the JSP into the HttpSession. For example:
public class SampleAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
String string = "TEST";
HttpSession session = request.getSession();
session.setAttribute("sampleString", string);
return mapping.findForward("sampleAction");
}
}
Then, in the JSP, I can simple reference "sampleString" and it won't change depending on the rendering Action.
Of course, the objects I'm using are much larger than a string, and I don't want to put objects in the session if I don't have to. Is there any way to just put an object into the page context or something, rather than the session, in order to share it among different JSPs?
I'm coming from the Rails world, so I'm very new to Struts and am finding myself a bit lost. I have to extend an existing application written in Struts. The program actually uses BeanAction to combine an ActionForm with an Action, so the example above isn't exactly what my code looks like.
Thanks for any help clearing up my confusion!