2 Replies Latest reply on Feb 8, 2011 2:44 AM by Anirudh Sasikumar

    Issues with communicating to JSP

    Adrien. Level 1

      I have some sample code that I got off a blog and was hoping you guys could fill me in on why it's not working properly as there demonstrations state it would. I have poured over the code and can't find the issue:


      The Flex code is as such:


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                          layout="absolute" applicationComplete="employees.send()">
                import mx.events.ValidationResultEvent;
                import mx.controls.Alert;private function validateEmpName():void{
                if (empNameValidator.validate().type == ValidationResultEvent.VALID)
                Alert.show("Employee name can not be blank");
                private function submitForm():void
                private function onResult(event:Event):void
           <mx:Model id="employeeModel">
           <mx:HTTPService id="employees" useProxy="false" method="POST" url="index.jsp"/>
           <mx:DataGrid dataProvider="{employees.lastResult.people.person}" width="50%">
                     <mx:DataGridColumn dataField="name" headerText="Name" />
                     <mx:DataGridColumn dataField="age" headerText="Age"/>
                     <mx:DataGridColumn dataField="skills" headerText="Skills"/>
           <mx:StringValidator id="empNameValidator" source="{empName}" property="text" triggerEvent=""/>
                <mx:Form width="100%" height="100%" x="50" y="400">
                     <mx:FormItem label="Enter name:" required="true">
                          <mx:TextInput id="empName" />
                     <mx:FormItem label="Enter age:">
                          <mx:TextInput id="age" />
                     <mx:FormItem label="Enter skills">
                          <mx:TextInput id="skills" />
                     <mx:Button label="Add Employee" click="validateEmpName()"/>


      While the JSP page is much simpler:


          Document   : index
          Created on : Feb 1, 2011, 10:34:13 AM
          Author     : Adam Balan
      <%@page import="java.io.PrintWriter"%>
      <%@page contentType="text/html" pageEncoding="UTF-8"%>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <title>JSP Page</title>
                          String employees = "<?xml version=\'1.0\' encoding=\'UTF-8\'?><people><person><name>Alex</name><age>22</age><skills>java, HTML, SQL</skills></person><person><name>Brandon Smith</name><age>21</age><skills>PowerScript, JavaScript, ActionScript</skills></person><person><name>Jeremy Plant</name><age>20</age><skills>SQL, C++, Java</skills></person>";
                          String name = request.getParameter("empName");
                          String age = request.getParameter("age");
                          String skills = request.getParameter("skills");
                          String newEmployee = "<person><name>" + name + "</name><age>" + 
                                  age + "</age><skills>" + skills + "</skills></person>";
                          if (name == null)
                              out.println(employees + "</people>");
                              out.println(employees + newEmployee + "</people>");



      So my question is this:


      Why is this JSP page not populating the data grid of the flex application with the information provided? This all connecting through a glassfish server.


      Also are there any solid example and or projects where you can connect Flex to JSP to send and recieve data?