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>
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.
This is the requirement and the approach taken by the management. Also, the project is using JSTL for the presentation. The jsp-jstl code also reads other element nodes from the xml for displaying values on the web page, so it is necessary for us to access the xml document (stored in the request scope) here... As part of this, i need to pass some values from the xml document to a utility method that does some processing and returns the processed data.
Could you please suggest the right way of: 1. Using JSTL, reading the xml value from a particular node, setting it in some variable and then passing it to the Java utility method using the example xml i put in my last post.
Just so that i can be sure, using the approach of having JSTL tags to read xml document (object stored in request scope), i.e value of a element node and then pass that value to a Java method is not technically possible - Is that correct ??
I have another question - when i use xml:set tag and assign the node using a var="val" attribute, i have the node with me. How is it that xml:out prints the value of var (which is val) on the screen/ web page, but when i do a pageContext.getAttribute("val"), i get the node object and not the actual value ? Isn't this a limitation of JSTL ??
posted 10 years ago
Hi Bear -
Another place that i needed this functionality was to format a number (e.g amount) after reading the value from the xml document. Say the value of amount on the xml node element is 3000. But on the web page (browser), it should display as 3,000.00
How can i do this in JSP after using the JSTL xml tag to read the value ?
The value of price now contains the actual value rather than the node.
However, i am still facing an issue with fmt:formatNumber jstl tag. I am not able to get the currency symbol. It just contains the amount/ currency value. I tried using currencySymbol as $ as well as currencyCode as USD, but it did not work. Can you please let me know my mistake ?