I have found a situation where I would like to include the same content on many pages by importing the output of an shared ActionBean.
What I would like to do is have an ActionBean which takes some parameters and does some processing and then returns a ForwardResolution to a JSP which renders the output of that ActionBean using standard Stripes constructs like ${actionBean.myValue
.
I would then like to "call" this ActionBean from other JSPs. This would have the effect of placing the output HTML from the first ActionBean into the Second JSP's output.
How can I do this?
You can get the desired result by using the <jsp:include>
tag.
SharedContentBean.java
@UrlBinding("/sharedContent")
public class SharedContentBean implements ActionBean {
String contentParam;
@DefaultHandler
public Resolution view() {
return new ForwardResolution("/sharedContent.jsp");
}
}
In your JSP
<!-- Import Registration Form here -->
<jsp:include page="/sharedContent">
<jsp:param value="myValue" name="contentParam"/>
</jsp:include>
web.xml
Make sure to add INCLUDE
to your <filter-mapping>
tag in web.xml:
<filter-mapping>
<filter-name>StripesFilter</filter-name>
<url-pattern>/*</url-pattern>
<servlet-name>StripesDispatcher</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>