读书人

跪flex和jsp通信的例子

发布时间: 2012-03-06 20:47:55 作者: rapoo

跪求一个flex和jsp通信的例子
跪求一个flex和jsp通信的例子,最好是自己编写过的,不要是网上有的,我在网上找了一天了,找到那个登入系统不能有用,不知道是什么原因啊,代码是这样的,有空也可以帮我看看
mxml代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:states>
<mx:State name="Logged In">
<mx:SetProperty target="{panel1}" name="width" value="95%"/>
<mx:SetProperty target="{panel1}" name="height" value="95%"/>
<mx:RemoveChild target="{password}"/>
<mx:RemoveChild target="{username}"/>
<mx:RemoveChild target="{label1}"/>
<mx:RemoveChild target="{Submit}"/>
<mx:RemoveChild target="{label2}"/>
<mx:SetProperty target="{panel1}" name="title" value="Today is Present"/>
<mx:AddChild relativeTo="{panel1}" position="lastChild">
<mx:Label x="10" y="10" text="Today is a gift"/>
</mx:AddChild>
<mx:AddChild relativeTo="{panel1}" position="lastChild">
<mx:Label x="10" y="36" text="That's way we call it the present!"/>
</mx:AddChild>
<mx:AddChild relativeTo="{panel1}" position="lastChild">
<mx:Label x="10" y="62" text="Liceven"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;

]]>
</mx:Script>
<mx:Script>


<![CDATA[

private function checkLogin(evt:ResultEvent):void
{

if(evt.result.loginResult == "yes")

{

currentState = "Logged In";

}

if(evt.result.loginResult == "no")

{

mx.controls.Alert.show('Invalid username/password');

}
}

]]>

</mx:Script>
<mx:HTTPService id="login_user" result="checkLogin(event)" showBusyCursor="true" method="POST"
url="C:\Documents and Settings\Administrator\workspace\J2EEFlexStu\flex_src\icons\loginCheck.jsp" useProxy="false">
<mx:request xmlns="">
<username>
{username.text}
</username>
<password>
{password.text}
</password>
</mx:request>
</mx:HTTPService>

<mx:Panel resizeEffect="Resize" width="250" height="200" layout="absolute" title="Login System" horizontalCenter="0" verticalCenter="-2" id="panel1">
<mx:Label x="10" y="10" text="Username:" id="label1"/>
<mx:TextInput x="10" y="36" id="username"/>
<mx:Label x="10" y="66" text="Password:" id="label2"/>


<mx:TextInput x="10" y="92" id="password" displayAsPassword="true"/>
<mx:Button x="10" y="122" label="Submit" id="Submit" click="login_user.send();"/>
</mx:Panel>

</mx:Application>

jsp代码:
<%
response.setContentType("text/xml");
out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
String userName = request.getParameter("username");
String password = request.getParameter("password");

//Here we do a simple checking to make sure userName equals to password

//and then outprints yes or not

String loginResult = "<loginResult>";
if (userName.equals(password)) {
loginResult += "yes";
} else {
loginResult += "no";
}
loginResult += "</loginResult>";

out.println(loginResult);
%>
上面那个URL我自己把它设置了 应该不会是URL的问题吧???

[解决办法]
没有这样的地址吧
url="C:\Documents and Settings\Administrator\workspace\J2EEFlexStu\flex_src\icons\loginCheck.jsp"

改成
url=".\icons\loginCheck.jsp"

读书人网 >flex

热点推荐