由于目前好多网友问关于flex与jsp的联系,现在我把有关它们联系的代码贴出来供大家参考.其实只要把jsp代码转换成XML开式就行,flex读取的是xml,下面是关于flex把值传给JSP和JSP把值传给FLEX.文件FlexJsp.mxml
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" applicationcomplete="employees.send()">
<mx:httpservice id="employees" method="POST" url="http://localhost:8080/employees.jsp" result="onResult(event)" useproxy="false"></mx:httpservice>
<mx:datagrid width="100%" dataprovider="{employees.lastResult.people.person}">
<mx:columns>
<mx:datagridcolumn headertext="Name" datafield="name"></mx:datagridcolumn>
<mx:datagridcolumn headertext="Age" datafield="age"></mx:datagridcolumn>
<mx:datagridcolumn headertext="Skills" datafield="skills"></mx:datagridcolumn>
</mx:columns>
</mx:datagrid>
<mx:stringvalidator id="empNameValidator" source="{empName}"></mx:stringvalidator> property="text" triggerEvent=""/>
<mx:model id="employeeModel">
<root></root>
<empname></empname>{empName.text}
<age></age>{age.text}
<skills></skills>{skills.text}
</mx:model>
<mx:form width="100%" height="100%">
<mx:formitem label="Enter name:" required="true">
<mx:textinput id="empName"></mx:textinput>
</mx:formitem>
<mx:formitem label="Enter age:">
<mx:textinput id="age"></mx:textinput>
</mx:formitem>
<mx:formitem label="Enter skills">
<mx:textinput id="skills"></mx:textinput>
</mx:formitem>
<mx:button label="Add Employee" click="validateEmpName()"></mx:button>
</mx:form>
<mx:script>
import mx.events.ValidationResultEvent;
import mx.controls.Alert;
private function validateEmpName():void{
if (empNameValidator.validate().type == ValidationResultEvent.VALID){
submitForm();
} else{
Alert.show("Employee name can not be blank");
}
}
private function submitForm():void {
employees.cancel();
employees.send(employeeModel);
}
private function onResult(event:Event):void{
trace('Got the result'); // works only in the debug mode
return;
}
]]>
</mx:script>
</mx:application>文件FlexJsp代码意思就不用解释了吧,相信大家都会。 JSP文件如下 放在tomcat的root下面
employees.jsp测试时应该启动tomcat,不然看不出效果。马上推出,flex与JSP,Hibernate,mysql 的程序代码。哎,不知道怎么弄好了发表之后成这个样子。。。。。