I am passing param value in include tag in jsp page like below
<s:include value="../../commonjspf/status.jspf">
<s:param name="mystatus" value="%{status}">
</s:param>
</s:include>
where status variable come from action class .
I want to access that mystatus param in status.jspf page in struts if tag to compare with my default values.
<s:if test ="">
</s:if>
or
<s:set name="" value =""/>
any of above tags.
how can i access ?
please suggest me .
Thanks.
To include JSP in another JSP file, we will use <jsp:include /> tag. It has a attribute page which contains name of the JSP file.
Include Tag This is used to include the contents of reusable content.
The include tag allows you include a template inside the current template. This is useful when you have a block of content that are the same for many pages.
Use the ${param.ParamName}
notation to access them, as mentioned in the reference below:
http://struts.apache.org/2.0.14/docs/include.html
A sample code:
Page 1:
<s:include value="testPage.jsp">
<s:param name="mystatus">TestThis</s:param>
</s:include>
Page 2:
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="mystatus" value="${param.mystatus}" scope="page"/>
<s:if test='%{#attr.mystatus == "TestThis"}'>
This is what we want
</s:if>
<s:else>
This is not what we want
</s:else>
Any additional params supplied to the included page are not accessible within the rendered page through the tag since no valuestack will be created. refer to the Struts2 documentation for details.
Struts2 Include tag
You can, however, access them in a servlet via the HttpServletRequest object or from a JSP page via a scriptlet.something like
${param.ParamName}
I would just like to throw this in as an alternative to using the struts include tag.
You can instead use the jsp:include
tag and use the struts s:push
tag to push parameters onto the stack and make them available in the included page, it adds an couple of extra lines into the jsp but is much more flexible as you can pass objects rather than just strings into the included JSP.
The nature of the push tag means once your done the parameters are poped from the stack again.
Primary JSP
<s:push value="#{'someStringParam':'some string', 'someObjectParam': someObject}">
<jsp:include page="../includes/user-tabs.jsp" />
</s:push>
Included JSP
<s:property value="someStringParam" />
<s:if test="someObjectParam.someValue > 10">
Result!
</s:else>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With