gpt4 book ai didi

java - 参数未从 flex 发送到 java

转载 作者:行者123 更新时间:2023-12-02 04:46:20 24 4
gpt4 key购买 nike

我想使用 HTTP 服务连接 flex 和 java。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
bcreationComplete="initApp();">
<fx:Script>
<![CDATA[
import mx.controls.Alert;

private function initApp():void {
b1.addEventListener(MouseEvent.CLICK, myEventHandler);
}

private function myEventHandler(event:Event):void {
Alert.show("An event occurred."+t1.text);

srv.send("abc");


}
]]>
</fx:Script>

<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:HTTPService id="srv" url="http://localhost:8080/JavaFlex/rest/flextest">

</s:HTTPService>
</fx:Declarations>
<s:Label>
Ur message

</s:Label>
<s:TextInput id="t1"/>
<s:Button id="b1" label="Submit" x="120" y="50">
</s:Button>
<mx:DataGrid x="220" y="150" dataProvider="{srv.lastResult}"/>
</s:Application>

我正在调用休息服务。调用 (find all) 方法,但未传递“msg”参数。这是我的休息服务。

@Path("/flextest")
public class chartServer {

@GET
@Produces({"text/plain"})
public String findAll(String msg) throws SQLException {
ArrayList<Integer> temp=new ArrayList<Integer>();
System.out.println("op is "+ msg);
System.out.println("Rest Api invoked");
chartData r= new chartData();
temp= (ArrayList<Integer>) r.data();
System.out.println("From rest "+temp);
return msg;
}

}

控制台中显示的输出是op是

为什么参数不显示?

最佳答案

问题出在这一行:

srv.send("abc");

根据HTTPService documentation ,您需要将名称-值对的对象传递给 send()。因此,您需要的是:

var values:Object = {};
values["msg"] = "abc";
srv.send(values);

关于java - 参数未从 flex 发送到 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29626550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com