我想從java返回值到Flex前端使用BlazeDs.Successfully Blazeds連接時檢索它顯示的值[對象Asynvtoken]沒有從java方法獲取值。而不是arrayCollection
我的Flex代碼:
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public function get_user():void
{
var token:AsyncToken = ro.getOperation('getUser').send();
user_grid.dataProvider = token.toString();
Alert.show(user_grid.dataProvider.toString());
}
private function fault(e:FaultEvent):void
{
Alert.show("code:\n" + e.fault.faultCode + "\n\nMessage:\n" + e.fault.faultString + "\n\nDetail:\n" + e.fault.faultDetail);
}
private function result(e:ResultEvent):void
{
userbtn.visible = false;
lnkbtn.visible = true;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:RemoteObject id="ro"
source="com.freelancer.GetUser"
fault="fault(event)"
destination="BlazeDsService">
<s:method name="getUser"
result="result(event)"/>
</s:RemoteObject>
</fx:Declarations>
<mx:DataGrid id="user_grid" x="-1" y="-1" width="705" height="356">
<mx:columns>
<mx:DataGridColumn headerText="Id" dataField="id"/>
<mx:DataGridColumn headerText="Name" dataField="name"/>
<mx:DataGridColumn headerText="Password" dataField="pwd"/>
</mx:columns>
</mx:DataGrid>
<s:Button x="322" y="429" id="userbtn" label="Get User" width="98"
height="23" cornerRadius="10" click="get_user()"/>
<mx:LinkButton x="331" y="429" id="lnkbtn" visible="false" label="Connected Please Wait Loading . . ."/>
我的Java代碼:
public class GetUser
{
public static void main(String[] argv)
{
System.out.println("-------- PostgreSQL " +
"JDBC Connection Testing ----------");
getUser();
}
public static List<User> getUser()
{
List<User> ls=new ArrayList<User>();
String host = "test";
String port = "1234";
String dbName = "test";
Connection connection = null;
try
{
connection = DriverManager.getConnection(
"jdbc:postgresql://" + host + ":" + port + "/" + dbName,"user", "user");
System.out.println("Database is connected");
String strSQL = "select * from test";
Statement st = connection.createStatement();
ResultSet rs=st.executeQuery(strSQL);
System.out.println("hi,query executed");
while(rs.next())
{
User user = new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setPwd(rs.getString("pwd"));
ls.add(user);
}
}
catch(Exception e)
{
System.out.println();
}
finally
{
try
{
connection.close();
}
catch (Exception ignored)
{
}
}
return ls;
}
}
如果有人知道的解決方案,請幫助我。
我合併兩個帳戶在一起。 [請閱讀關於基於Cookie的帳戶的這個Faq條目。](http://meta.stackexchange.com/questions/44557/why-should-i-register-my-account/44562/1228)另外,StackOverflow不是一個論壇;如果您有新問題,請提出一個新問題。如果你想在你的問題中包含更多信息,請[編輯](http://stackoverflow.com/posts/5960343/edit)。如果您想與其中一位已回答的人進行互動,您可以留下評論。 – Will 2011-05-11 13:16:57