StockDetails.java
public class StockDetails {
public String getDetailsBySymbol(String symbol){
StockQuote stockQuote = new StockQuote();
StockQuoteSoap stockQuoteSoap = stockQuote.getStockQuoteSoap();
return stockQuoteSoap.getQuote(symbol);
}
}
并以xml格式返回stockquote
在客户端jsp文件index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Dwr Example</title>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<script type='text/javascript' src='dwr/interface/StockDetails.js'>
</script>
<script>
function getMessageFromServer()
{
var symbol = DWRUtil.getValue("companySymbol");
DWRUtil.setValue("response", "");
StockDetails.getDetailsBySymbol(gotResult, symbol);
}
function gotResult(symbol)
{
DWRUtil.setValue("response", symbol);
}
</script>
</head>
<body>
<p>
<input type="text" id="companySymbol"></input><br>
<button onclick="getMessageFromServer()">Click</button><br><br>
</p>
<p>
<span id="response">Response appear here..</span>
</p>
</body>
</html>
它显示为普通文本,我如何显示结构格式,如
公司名称:
起拍价:
收盘价:
任何想法?
答案 0 :(得分:0)
您可以将其打印为表格。例如,考虑,
<td id='demo'>
//DWR elements to be populated here
</td>
使用javascript,
dwr.util.addRows( "demo", [symbol], cellFuncs, { escapeHtml:false });
答案 1 :(得分:0)
您可以使用downloadxml.js
来解析数据,构建一个html表,并在使用jquery填充字段之后
`var xml = xmlParse(data);
for(var i = 0; i&lt; data.length; i ++){
$("#fila"+i).find("#field1").text(data[i].field1);
$("#fila"+i).find("#field2").text(data[i].field2);
...........
}
`