Search code examples
jspservletsstruts

How to do the task of "<jsp:include page="servletName" />" using Struts


In my JSP page, a tag <jsp:include page="servletName" /> has been added. Here servletName is is HttpServlet Class and that class add some attributes to Request object. Then, again in the jsp page, the values set to the request object are retrieved (this thing has been done to reduce the line of codes in the jsp page).

I want to do this in Struts 2 application.

I want to call an action class (something like <jsp:include /> in a normal jsp application) and then that class set some values to Request object(Value Stack) . Then those values should be retrieved in the jsp class using Struts Tags.

How Can I do this?

Also, how can I send a request parameter bound to the jsp page and send it to the action class? here shows something what I want:

<s:action name="Login" flush="true" executeResult="true" namespace="/secure"/>   

But it is not clear for me how to write execute() and struts.xml and the attributes used. any one can clear it for me please?


Solution

  • Use the <s:action> tag.

    I question the need for this, however; if this is something done frequently enough to warrant this, consider using a base action class that implements Preparable, and create an app-specific sub-class means of adding behavior for actions that require their own prepare.

    IMO relying on the view to add objects it needs is a violation of concern separation.