0 Replies Latest reply on Aug 27, 2008 6:39 AM by Sankar Kethineni

    Flex with JSP

    Sankar Kethineni
      Hi All,
      here is the scenario , am trying to connect to the my-sql database and get the data from the DB in the JSP page ( employee.jsp) and trying to displaying those records through the MXML using the DataGrid as shown in the following code

      I have deployed that employee.jsp in the Tomcat Server and am able to display those recoeds, but the problem is am not able to display those records through the MXML.

      can anyone identify what the problem is and help me ?

      sample.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      initialize="emp.send()">

      <!--<mx:Script>
      <![CDATA[
      private function onResult(event:Event):void
      {
      return;
      }
      ]]>
      </mx:Script>-->

      <mx:HTTPService id="emp" method="POST" url=" http://localhost:8080/employee.jsp"/>

      <mx:DataGrid dataProvider="{emp.lastResult.employees.employee}" x="100" y="100">
      <mx:columns>
      <mx:DataGridColumn dataField="firstname" headerText="First Name"/>
      <mx:DataGridColumn dataField="lastname" headerText="Last Name"/>
      <mx:DataGridColumn dataField="age" headerText="Age"/>
      <mx:DataGridColumn dataField="designation" headerText="Designation"/>
      </mx:columns>
      </mx:DataGrid>

      </mx:Application>


      employee.jsp


      <%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
      <%@ page import="java.sql.*" %>
      <employees>
      <%
      try
      {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sankar","root","sankar");
      out.println("Successfully connected to my-sql <br>");

      Statement stmt=con.createStatement();
      ResultSet rs=stmt.executeQuery("select * from employee");
      while(rs.next())
      {
      %>

      <employee>
      <firstname><%= rs.getString(1) %></firstname>
      <lastname><%= rs.getString(2) %></lastname>
      <age><%= rs.getString(3) %></age>
      <designation><%= rs.getString(4) %></designation>
      </employee>

      <% }

      con.close();

      }
      catch(Exception e)
      {
      System.out.println("Exception due to:"+e);
      }
      %>
      </employees>