Flex JSP with HttpService

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值