写WAP Script出错

phoenixlf 2007-12-05 06:43:57
在此先谢谢各位啦.
我用的是Tomcat作的WAP服务器,模拟器采用的是WinWAP for windows
我使用WinWAP直接访问文件是不会出错的.但是当我在WinWAP的地址栏里输入本地访问地址的时候,却在调用函数脚本的时候出错了.基本上都是报一些脚本错误,我很不明白,为什么能直接访问,而不能在地址栏里输入http://localhost:8080/currency.wml来访问.请大家帮个忙.
程序代码如下:
currency.wml如下:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Currency" newcontext="true">
<p>
Amount: <input format="*N" name="amount"
title="Amount:"/>
<select name="from" value="USD" title="From:">
<option value="DEM">German Mark</option>
<option value="FRF">French Franc</option>
<option value="FIM">Finnish Markka</option>
<option value="USD">US Dollar</option>
</select>
<select name="to" value="FIM" title="To:">
<option value="DEM">German Mark</option>
<option value="FRF">French Franc</option>
<option value="FIM">Finnish Markka</option>
<option value="USD">US Dollar</option>
</select>
<br/>= <u>$(conversion)</u>
<do type="accept" label="Calculate">
<go
href="currency.wmls#convert('conversion','$(from)','$(to)',
$(amount))"/>
</do>
<do type="help" label="Help">
<go href="#card1_help"/>
</do>
</p>
</card>

<card id="card1_help" title="Help">
<onevent type="onenterforward">
<go href="currency.wmls#getInfoDate('date')"/>
</onevent>
<p>
The currency rates were obtained from the Federal
Reserve Bank of New York on $(date).
<do type="prev" label="Back">
<prev/>
</do>
</p>
</card>
</wml>

下面这个是currency.wmls的代码(也就是脚本代码了)
/*
* Return the date when the data was generated.
*
*@param varName - the variable to store the results
*/
extern function getInfoDate(varName) {
WMLBrowser.setVar(varName,"October 29 1998");
WMLBrowser.refresh();
}
/*
* Calculate the exchange rate
*
*@param varName - the variable to store the results
*@param amount - the amount to convert
*@param from - the original currency
*@param to - the currency to convert to
*@return a string containing the converted amount; or an
error
* if "from" and/or "to" is not supported.
*/
extern function convert(varName,from,to,amount) {
var multiplier = 0.0;
var returnString = "Not Available";
var result;
if (from == "DEM") {
/*
* German Mark
*/
var DEM_FIM = 0.328728;
var DEM_FRF = 0.298331;
var DEM_USD = 1.653500;
if (to == "DEM")
multiplier = 1.0;
else if (to == "FIM")
multiplier = DEM_FIM;
else if (to == "FRF")
multiplier = DEM_FRF;
else if (to == "USD")
multiplier = DEM_USD;
} else if (from == "FIM") {
/*
* Finnish Markka
*/
var FIM_DEM = 3.042032;
var FIM_FRF = 0.907533;
var FIM_USD = 5.030000;
if (to == "FIM")
multiplier = 1.0;
else if (to == "DEM")
multiplier = FIM_DEM;
else if (to == "FRF")
multiplier = FIM_FRF;
else if (to == "USD")
multiplier = FIM_USD;
} else if (from == "FRF") {
/*
* French Franc
*/
var FRF_DEM = 3.351981;
var FRF_FIM = 1.101889;
var FRF_USD = 5.542500;
if (to == "FRF")
multiplier = 1.0;
else if (to == "FIM")
multiplier = FRF_FIM;
else if (to == "DEM")
multiplier = FRF_DEM;
else if (to == "USD")
multiplier = FRF_USD;
} else if (from == "USD") {
/*
* US Dollar
*/
var USD_DEM = 0.604778;
var USD_FIM = 0.198807;
var USD_FRF = 0.180424;
if (to == "USD")
multiplier = 1.0;
else if (to == "FIM")
multiplier = USD_FIM;
else if (to == "FRF")
multiplier = USD_FRF;
else if (to == "DEM")
multiplier = USD_DEM;
}
if (multiplier != 0.0) {
/*
* Make the calcualtion
*/
result = amount / multiplier;
returnString = String.toString(result);
returnString = String.format("%.2f", returnString);
}
/*
* Return the results to the browser
*/
WMLBrowser.setVar(varName,returnString);
WMLBrowser.refresh();
};
我可以直接打开WinWAP,然后点击currency.wml,这样是可以访问的,但是当我在地址栏里输入http://localhost:8080/currency.wml 来访问的时候却会出现错误.请先行了给予点经验指导.不甚感激.
...全文
112 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenwei023 2008-07-31
  • 打赏
  • 举报
回复
眞吥簡單
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
好像没那么简单,呵呵.
cangwu_lee 2007-12-07
  • 打赏
  • 举报
回复

看來是變量名稱不能用這麼簡單的,將from/to改成複雜點的,如 CurFrom/CurTo 。
還有,最好判斷一下amount是否有效。
cangwu_lee 2007-12-06
  • 打赏
  • 举报
回复

都沒有說具體的錯誤信息。

790

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 其他移动相关
社区管理员
  • 移动开发其他问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧