Search code examples
jspjstlstruts-1

not able to use bean:define variable in non stuts tags in a jsp page


I am able to use "acctNum" inside scriptlet as <%=acctNum %> with in the block of statements inside tag as mentioned in the below code.

<logic:greaterEqual name="childArraySize" value="1">
 <bean:define id="acctNum" name="overviewSel" property="accountNumber" type="String"/>
 <logic:equal name="accountNumber" value="<%=acctNum %>">
    <bean:define id="STItemIndex" name="ItemIndex"/>
    <bean:define id="overviewCh" name="overviewSel" type="com.beans.statements.StatementAccount"/>
    <bean:define id="arraySize"  name="childArraySize"/>
    <bean:define id="statementAccountTypeDesc" name="statementAccountTypeDescSel"/>
  </logic:equal>    
</logic:greaterEqual>

But I'm not able to use this in the code anywhere after </logic:greaterEqual> it gives me intermittent error when using it in a scriptlet i.e., inside <% --- %>, I am getting 'acctNum can not be resolved'

But it works if I use it in any struts tag like <bean:write name="acctNum">

Please let me know if there is a work around for this


Solution

  • I was able to resolve this issue.

    I found that all stuts tags are fine with getting the values, but if I'm using scriptlet/ JSTL tags I was not getting the values,

    For that I had to do a workaround and use it like this <%pageContext.getAttribute("acctNum") %> in case of a scriptlet and for JSTL <c:out value="pageContext.acctNum">