Flex JSP with httpservice

Source: Internet
Author: 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 = "User List" 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 = drivermanager. getconnection (URL);
statement = connection. createstatement ();
string SQL = "select * from" + tablename;
resultset rs = statement.exe cutequery (SQL);
resultsetmetadata rmeta = Rs. getmetadata ();
int numcolumns = rmeta. getcolumncount ();
out. write (" ");
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

---- Database: 'test' ---- -------------------------------------------------------- table structure 'employe' -- Create Table if not exists 'employe' ('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; ---- export the data in the table 'employe' -- insert into 'employe' ('name', 'street', 'city', 'state ', 'zip') values ('Tom ', 'tiance', 'shanghai', 'China', '20140901'), ('Peter', 'tiance', 'shanghai ', 'China', '123'), ('mad li', 'tiance', 'shanghai', 'China Sh', '123'), ('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

 

this article from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/maxgong2005/archive/2009/04/12/4067149.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.