Flex JSP with HttpService

來源:互聯網
上載者:User

1. Create Flex simple application with Flex Builder 3

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
  backgroundColor="#FFFFFF">
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.rpc.events.ResultEvent;
  
   [Bindable]
   private var employeeData:ArrayCollection;
   private function resultHandler(event:ResultEvent):void{
    employeeData = event.result.employees.employee;
   }
  ]]>
 </mx:Script>
 
 <mx:HTTPService id="employeeService" url="http://localhost:8080/FlexServer/employees.jsp"
   result="resultHandler(event)"/>
 
 <mx:DataGrid dataProvider="{employeeData}" width="100%" height="264" y="36"/>
 <mx:Button click="employeeService.send()" y="308" label="Refresh" horizontalCenter="15"/>
 <mx:Label y="10" text="使用者列表" horizontalCenter="-14" fontWeight="bold" color="#0C0B3C" fontSize="18" fontFamily="Arial"/>
</mx:Application>

2. Create Static web project FlexServer and one JSP page named employees.jsp with Eclipse J2ee ganymede

<?xml version="1.0" encoding="utf-8"?>
<%@ page contentType="text/xml; charset=gb2312"%>
<%
 response.setHeader("Pragma", "No-cache");
 response.setHeader("Cache-Control", "no-cache");
 response.setDateHeader("Expires", 0);
%>
<%@ page language="java"%>
<%@ page import="com.mysql.jdbc.Driver"%>
<%@ page import="java.sql.*"%>

<%
 String driverName = "com.mysql.jdbc.Driver";
 String userName = "root";
 String userPasswd = "";
 String dbName = "test";
 String tableName = "employee";

 String url = "jdbc:mysql://localhost/" + dbName + "?user="
   + userName + "&password=" + userPasswd;
 Class.forName("com.mysql.jdbc.Driver").newInstance();
 Connection connection = DriverManager.getConnection(url);
 Statement statement = connection.createStatement();
 String sql = "SELECT * FROM " + tableName;
 ResultSet rs = statement.executeQuery(sql);
 ResultSetMetaData rmeta = rs.getMetaData();
 int numColumns = rmeta.getColumnCount();
 out.write("<employees>");
 while (rs.next()) {

  out.write("<employee>");
  out.write("<name>");
  out.write(rs.getString("name"));
  out.write("</name>");
  out.write("<street>");
  out.write(rs.getString("street"));
  out.write("</street>");
  out.write("<city>");
  out.write(rs.getString("city"));
  out.write("</city>");
  out.write("<state>");
  out.write(rs.getString("state"));
  out.write("</state>");
  out.write("<zip>");
  out.write(rs.getString("zip"));
  out.write("</zip>");
  out.write("</employee>");

 }
 out.write("</employees>");
 rs.close();

 statement.close();
 connection.close();
%>

3. Mysql DB script

---- 資料庫: `test`---- ------------------------------------------------------------ 表的結構 `employee`--CREATE TABLE IF NOT EXISTS `employee` (  `name` varchar(20) NOT NULL,  `street` varchar(100) NOT NULL,  `city` varchar(20) NOT NULL,  `state` varchar(20) NOT NULL,  `zip` varchar(10) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;---- 匯出表中的資料 `employee`--INSERT INTO `employee` (`name`, `street`, `city`, `state`, `zip`) VALUES('tom', 'Tianshan', 'Shanghai', 'China', '200000'),('peter', 'Tianshan', 'Shanghai', 'China', '200000'),('Mad Li', 'Tianshan', 'Shanghai', 'China sh', '200000'),('test', 'MM', 'TT', 'kk', 'test');

4. mysql jdbc driver

mysql-connector-java-5.0.8-bin.jar

5. mysql

embedded in Xampp1.7

Appendix: about remoteObject usage with BladeDS

http://bbs.actionscript3.cn/thread-9982-1-1.html

 

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/maxgong2005/archive/2009/04/12/4067149.aspx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.