flex 与后台交互方式之HTTPService的问题(三)。
mxml文件代码:<?xmlversion="1.0"encoding="utf-8"?><s:Applicationxmlns:fx="http://ns.adobe....
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">
<fx:Script>
import mx.controls.Alert;
import mx.events.ListEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public function resultH(a:ResultEvent):void{
//var str:String=a.result.toString();????????
//outvalue.text=stt;
}
public function faultH(a:FaultEvent){
Alert.show(a.fault.message);
}
</fx:Script>
<s:Panel x="91" y="16" width="466" height="264" title="View">
<s:TextArea x="73" y="36" width="132" id="valuetext"/>
<s:TextArea x="226" y="36" width="138" id="outvalue"/>
<s:Label x="101" y="10" text="输入" width="76" height="18"/>
<s:Label x="278" y="12" text="输出" width="76" height="18"/>
<s:Button id="b" x="25" y="200" label="点击" click="hs.send()"/>
</s:Panel>
<fx:Declarations>
<mx:HTTPService id="hs" showBusyCursor="true" resultFormat="text" url="test.jsp" method="POST" result="resultH(event)" fault="faultH(event)">
<mx:request>
<valuet>{valuetext.text}</valuet>
</mx:request>
</mx:HTTPService>
</fx:Declarations>
</s:Application>
jsp代码如下:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String str=request.getParameter("valuet");
String returnvakue="";
if(str==null){
returnvakue="fail";
}else{
returnvakue="success";
}
out.println("<?xml version='1.0' encoding='utf-8'?>");
out.println("<root>");
out.println("<sta>"+str+"</sta>");
out.println("</root>");
%>
</body>
</html>
问题如下:
现在可以把前台的值传到后台,后台也能把值传到前台。但是经过测试传回来的值是整个jsp页面的内容。我想取得上jsp代码中变量returnvakue传到前台去?怎么办?求解。 展开
<?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">
<fx:Script>
import mx.controls.Alert;
import mx.events.ListEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public function resultH(a:ResultEvent):void{
//var str:String=a.result.toString();????????
//outvalue.text=stt;
}
public function faultH(a:FaultEvent){
Alert.show(a.fault.message);
}
</fx:Script>
<s:Panel x="91" y="16" width="466" height="264" title="View">
<s:TextArea x="73" y="36" width="132" id="valuetext"/>
<s:TextArea x="226" y="36" width="138" id="outvalue"/>
<s:Label x="101" y="10" text="输入" width="76" height="18"/>
<s:Label x="278" y="12" text="输出" width="76" height="18"/>
<s:Button id="b" x="25" y="200" label="点击" click="hs.send()"/>
</s:Panel>
<fx:Declarations>
<mx:HTTPService id="hs" showBusyCursor="true" resultFormat="text" url="test.jsp" method="POST" result="resultH(event)" fault="faultH(event)">
<mx:request>
<valuet>{valuetext.text}</valuet>
</mx:request>
</mx:HTTPService>
</fx:Declarations>
</s:Application>
jsp代码如下:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String str=request.getParameter("valuet");
String returnvakue="";
if(str==null){
returnvakue="fail";
}else{
returnvakue="success";
}
out.println("<?xml version='1.0' encoding='utf-8'?>");
out.println("<root>");
out.println("<sta>"+str+"</sta>");
out.println("</root>");
%>
</body>
</html>
问题如下:
现在可以把前台的值传到后台,后台也能把值传到前台。但是经过测试传回来的值是整个jsp页面的内容。我想取得上jsp代码中变量returnvakue传到前台去?怎么办?求解。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询