flex与java交互问题,将flex的类对象放入httpservice的request中,为什么在java端取出来是空对象??
大侠指点,为什么user对象是空的???Flex端:MyUser.as如下:packageclient{[RemoteClass(alias="mybean.User")...
大侠指点,为什么user对象是空的???
Flex端:
MyUser.as如下:
package client
{
[RemoteClass(alias="mybean.User")]
public class MyUser
{
private var Id:String;
private var Name:String;
public function MyUser()
{
}
public function getName():String
{
return this.Name;
}
public function setName(Name:String):void
{
this.Name = Name;
}
public function getId():String
{
return this.Id;
}
public function setId(Id:String):void
{
this.Id = Id;
}
}
Bean_Client.mxml如下:
<?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">
<s:layout>
<s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>
</s:layout>
<fx:Script>
<![CDATA[
import client.MyUser;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
public var us:MyUser=new MyUser();
protected function service_faultHandler(event:FaultEvent):void
{
// TODO Auto-generated method stub
Alert.show("wrong");
}
protected function service_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
Alert.show("ok");
}
protected function button1_clickHandler(event:MouseEvent):void
{
us.setId("myid");
us.setName("joy");
Alert.show(us.getId()+us.getName());
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:HTTPService id="service" fault="service_faultHandler(event)" url="http://localhost:8080/Bean/BeanServlet" result="service_resultHandler(event)">
<s:request>
<id>{myId.text}</id>
<name>{myname.text}</name>
<bean>{us}</bean>
</s:request>
</s:HTTPService>
</fx:Declarations>
<s:HGroup x="279" y="203" width="400" height="300">
<s:TextInput id="myId"/>
<s:TextInput id="myname"/>
<s:Button label="servlet" click="service.send()"/>
<s:Button label="fuzhi" click="button1_clickHandler(event)"/>
</s:HGroup>
</s:Application>
java端:
server的doGet方法如下:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
User user=(User)request.getAttribute("bean");
String id=request.getParameter("id");
String name=request.getParameter("name");
System.out.print(id+" "+name);
// System.out.print(user.getId()+user.getName());
}
User.java如下:
package mybean;
public class User {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
} 展开
Flex端:
MyUser.as如下:
package client
{
[RemoteClass(alias="mybean.User")]
public class MyUser
{
private var Id:String;
private var Name:String;
public function MyUser()
{
}
public function getName():String
{
return this.Name;
}
public function setName(Name:String):void
{
this.Name = Name;
}
public function getId():String
{
return this.Id;
}
public function setId(Id:String):void
{
this.Id = Id;
}
}
Bean_Client.mxml如下:
<?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">
<s:layout>
<s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>
</s:layout>
<fx:Script>
<![CDATA[
import client.MyUser;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
public var us:MyUser=new MyUser();
protected function service_faultHandler(event:FaultEvent):void
{
// TODO Auto-generated method stub
Alert.show("wrong");
}
protected function service_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
Alert.show("ok");
}
protected function button1_clickHandler(event:MouseEvent):void
{
us.setId("myid");
us.setName("joy");
Alert.show(us.getId()+us.getName());
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:HTTPService id="service" fault="service_faultHandler(event)" url="http://localhost:8080/Bean/BeanServlet" result="service_resultHandler(event)">
<s:request>
<id>{myId.text}</id>
<name>{myname.text}</name>
<bean>{us}</bean>
</s:request>
</s:HTTPService>
</fx:Declarations>
<s:HGroup x="279" y="203" width="400" height="300">
<s:TextInput id="myId"/>
<s:TextInput id="myname"/>
<s:Button label="servlet" click="service.send()"/>
<s:Button label="fuzhi" click="button1_clickHandler(event)"/>
</s:HGroup>
</s:Application>
java端:
server的doGet方法如下:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
User user=(User)request.getAttribute("bean");
String id=request.getParameter("id");
String name=request.getParameter("name");
System.out.print(id+" "+name);
// System.out.print(user.getId()+user.getName());
}
User.java如下:
package mybean;
public class User {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询