Hello,
Is there a way to pass the value from xml document using JSTL tags to a
Java class
In my application, i have an xml document which is saved in the request object in the
Servlet Controller. In my
jsp, i would like to read the value from some xml nodes and pass it to my java class. But i am unable to do so.
If i do an x:out it works, but i need to pass the value of the xml node to the Java method.
xml snippet:
<ACCOUNT>
<ACCOUNT_ID>12345</ACCOUNT_ID>
<ACCOUNT_NICKNAME>testAcc</ACCOUNT_NICKNAME>
<balance>
<loan_balance>1000</loan_balance>
</balance>
</ACCOUNT>
<ACCOUNT>
<ACCOUNT_ID>45678</ACCOUNT_ID>
<MASKED_ACCOUNT_NUMBER>xxxx5678</MASKED_ACCOUNT_NUMBER>
<balance>
<loan_balance>2000</loan_balance>
</balance>
</ACCOUNT>
The code is below.
<x:set select="ACCOUNT_ID" var="accountId"/>
<x:choose>
<x:when select="ACCOUNT_NICKNAME"><x:set select="ACCOUNT_NICKNAME" var="account"/></x:when>
<x:otherwise><x:set select="MASKED_ACCOUNT_NUMBER" var="account"/></x:otherwise>
</x:choose>
<x:choose>
<x:when select="balance/loan_balance"><x:set select="balance/loan_balance" var="balance2"/></x:when>
<x:otherwise><c:set var="balance2" value="N/A"/></x:otherwise>
</x:choose>
Now i want to pass the value contained in the variables - accountId, account and balance2 to a java method
<% util.setValues(accountId, account, balance2) where util is defined using jsp:useBean tag
I also tried using (
String)pageContext.getAttribute("accountId") to pass the value, but it does not work. I also tried adding /text in the select clause, but when i print it (say account_id) on the screen, it displays [[#text: 12345]]
I would greatly appreciate it if anybody could let me know where i am wrong and what is the correct way of achieving this.
Thanks in advance.