1

我想将 mxml 文件重定向到 servlet 并在 servlet 上打印代码,但是当我使用导航到 url 代码时,输​​出显示servlet 页面中 textinput 字段的值,请帮助我澄清问题 mxml 和 servlet 的基本编码下面给出

MXML 文件

<s:Application...>
<fx:Script>
<![CDATA[
  import flash.net.navigateToURL;
  import mx.controls.*;
  import mx.events.Request;
  import mx.rpc.events.FaultEvent;
  import mx.rpc.events.ResultEvent;

  public function resultHandler(event : ResultEvent):void
  {             
    navigateToURL(new URLRequest('Srvlt'),'_self')
  }
  public function faultHandler(event : FaultEvent):void
  {
    Alert.show("error");
  }
]]>
</fx:Script>

<fx:Declarations>
  <s:HTTPService id="service" url="Srvlt" result="resultHandler(event)" fault="faultHandler(event)" method="GET" showBusyCursor="true" resultFormat="text">
    <s:request xmlns="">
      <email>{email.text}</email>
      <pass>{pass.text}</pass>
    </s:request>
  </s:HTTPService>
</fx:Declarations>
<s:VGroup verticalAlign="middle">
  <s:FormItem label="E-mail : ">
    <s:TextInput id="email" />
  </s:FormItem>
  <s:FormItem label="Password :">
    <s:TextInput id="pass" displayAsPassword="true" />
  </s:FormItem>
  <mx:Button label="Submit" click="service.send()" />
</s:VGroup>
</s:Application>

servlet的get方法编码如下

String e = request.getParameter("email");
String p = request.getParameter("pass");
String resul;
PrintWriter out = response.getWriter();
resul = "Hi i am servlet, your username is " + e + " & password is " + p + ". are they correct ?";
out.print(resul);
4

1 回答 1

0

您在应用程序中发送 2 个不同的请求。第一个是HTTPService,第二个是URLRequest

<s:HTTPService id="service" url="Srvlt" result="resultHandler(event)"
fault="faultHandler(event)" method="GET" showBusyCursor="true" resultFormat="text">
    <s:request xmlns="">
        <email>{email.text}</email>
        <pass>{pass.text}</pass>
    </s:request>
</s:HTTPService>

处理结果时,您可以通过ResultEvent对象获取响应字符串

public function resultHandler(event : ResultEvent):void
{
    Alert.show(event.result); // you'll see "Hi i am servlet..." here
}

您现在可以使用此字符串。

但是如果你想用结果文本打开新页面,那么你不需要使用HTTPService. 使用URLRequest类。

var request:URLRequest = new URLRequest("Srvlt");
var variables:URLVariables = new URLVariables();
variables.email = email.text;
variables.pass = pass.text;
request.data = variables;
navigateToURL(request);

所以,你现在做错了。不要发送 2 个请求。选择其中一个HTTPService并在应用程序内处理结果,或者navigateToURL如果URLRequest您只想在新窗口中显示响应。

于 2012-10-19T08:47:51.080 回答