如何从jsp中获取xml文件中的值?

时间:2021-05-14 15:42:56

Hey i have a situation in which i need to pass some variable value in jsp to xml file.

嘿,我有一种情况,我需要将jsp中的一些变量值传递给xml文件。

for example if i have int a = 10;

例如,如果我有int a = 10;

and i want to pass value of "a" to xml file which is something like:-

我想将“a”的值传递给xml文件,如下所示:

<graph caption='Estimated Renewal Cost' xAxisName='Year' yAxisName='Units (US Dollars)' showNames='1' decimalPrecision='0' formatNumberScale='0'>
    <set name='Backlog' value='19273773' color='AFD8F8' />

</graph>

so in i want the value of "a" to be brought at value attribute of set tag in xml.

所以在我想要“a”的值被带到xml中set标签的value属性。

Actually i'm using fusion charts to generate graph and want to have dynamic graph which may change according to my jsp page. And as far as i know fusion charts only accept data in xml format.

实际上我正在使用融合图表生成图表,并希望拥有可能根据我的jsp页面改变的动态图表。据我所知,融合图表只接受xml格式的数据。

I have no experience with xml.

我没有使用xml的经验。

1 个解决方案

#1


1  

Your question doesn't make much sense. An XML file is just that: a file. It doesn't contain any executable or interpreted statement.

你的问题没有多大意义。 XML文件就是:一个文件。它不包含任何可执行文件或解释语句。

You probably want to dynamically generate an XML file (or stream), but unless the output generated by the JSP is this XML file (after all, JSPs typically generate (X)HTML, and can be used to generate other kinds of XML documents), it's not really a task that a JSP should do. A servlet is the place where such a task should be done.

您可能希望动态生成XML文件(或流),但除非JSP生成的输出是此XML文件(毕竟,JSP通常生成(X)HTML,并且可用于生成其他类型的XML文档) ,这不是JSP应该做的任务。 servlet是应该完成这项任务的地方。

If you want to generate an XML document, you have many choices: DOM, JDOM, dom4j, JAXB, or even plain string concatenation (although I would not recommend it, except if all you need to do is generating such a small document with only one dynamic attribute).

如果你想生成一个XML文档,你有很多选择:DOM,JDOM,dom4j,JAXB,甚至是普通的字符串连接(虽然我不推荐它,除非你需要做的只是生成这么小的文件而只是一个动态属性)。

#1


1  

Your question doesn't make much sense. An XML file is just that: a file. It doesn't contain any executable or interpreted statement.

你的问题没有多大意义。 XML文件就是:一个文件。它不包含任何可执行文件或解释语句。

You probably want to dynamically generate an XML file (or stream), but unless the output generated by the JSP is this XML file (after all, JSPs typically generate (X)HTML, and can be used to generate other kinds of XML documents), it's not really a task that a JSP should do. A servlet is the place where such a task should be done.

您可能希望动态生成XML文件(或流),但除非JSP生成的输出是此XML文件(毕竟,JSP通常生成(X)HTML,并且可用于生成其他类型的XML文档) ,这不是JSP应该做的任务。 servlet是应该完成这项任务的地方。

If you want to generate an XML document, you have many choices: DOM, JDOM, dom4j, JAXB, or even plain string concatenation (although I would not recommend it, except if all you need to do is generating such a small document with only one dynamic attribute).

如果你想生成一个XML文档,你有很多选择:DOM,JDOM,dom4j,JAXB,甚至是普通的字符串连接(虽然我不推荐它,除非你需要做的只是生成这么小的文件而只是一个动态属性)。