-1

I want to assign ${element.cpReferralDtlsId} data variable.


<c:forEach items="${indentIssueData}" var="element">  
<tr>                          
<%
 String data =  ${element.cpReferralDtlsId};
%>
<td><%=++data %></td>   
</tr>
</c:forEach>`
  • 1
    When asking for help, it is good if you provide all information about what the problem is - eg. What error message (and on which line) are you seeing ???? I’m guessing you are facing a similar issue to this : https://stackoverflow.com/a/23601089/681444 – racraman Apr 05 '23 at 08:32
  • How is `++data` meant to work with a variable of type `String`? – Thomas Apr 05 '23 at 08:32
  • Also note that there is no Javascript in your snippet at all, so that tag seems to be superfluous. – Thomas Apr 05 '23 at 08:33

1 Answers1

0
<c:forEach items="${indentIssueData}" var="element">  
<tr>                          
<%
 String data = element.getCpReferralDtlsId();
%>
<td><%=++data %></td>   
</tr>
</c:forEach>

Note that the ${} syntax is used in JSP expressions to evaluate and insert the result of a Java expression into the generated HTML. However, in this case, since we are already inside a scriptlet (<% %>) block, we don't need to use ${} to reference the element object. We can simply use the variable name directly.

fenzy
  • 1
  • Hi,Thank you for reply . I want to use 'data' variable value in some other logic.based on 'data' variable value i have written some other. Can you let me know how to get element.CpReferralDtlsId value in data varible . – Venkatesh Bvr Apr 05 '23 at 09:20
  • <% String someOtherValue = ""; if(data.equals("123")) { someOtherValue = "ABC"; } else { someOtherValue = "DEF"; } %> – fenzy Apr 05 '23 at 12:47