Chinaunix首页 | 论坛 | 博客
  • 博客访问: 362192
  • 博文数量: 100
  • 博客积分: 2586
  • 博客等级: 少校
  • 技术积分: 829
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 15:20
个人简介

我是一个Java爱好者

文章分类

全部博文(100)

文章存档

2014年(2)

2013年(7)

2012年(2)

2010年(44)

2009年(28)

2008年(17)

我的朋友

分类:

2009-04-10 15:12:57

Working with JavaServer Pages

You can use a Flex HTTPService component in conjunction with a JSP page and a SQL database management system to display the results of a database query in a Flex application and insert data into a database. You can call a JSP page with GET or POST to perform a database query. You can then format the query result data in an XML structure and return the XML structure to the Flex application in the HTTP response. When the result has been returned to the Flex application, you can display it in one or more user interface controls.

MXML code

The Flex application in the following example calls a JSP page that retrieves data from a SQL database. It formats database query results as XML and returns the XML to the Flex application, where it is bound to the dataProvider property of a DataGrid control and displayed in the DataGrid control.



    
    

     
    
    
    

The HTTPService's send() method makes the call to the JSP page. This call is made in the click event of the Button in the MXML file.

The resultFormat property of the HTTPService component is set to object, so the data is sent back to the Flex application as a graph of ActionScript objects. This is the default value for the resultFormat property. Alternatively, you can use a result format of e4x to return data as an XMLList object on which you can perform ECMAScript for XML (E4X) operations. Switching the resultFormat property to e4x requires the following minor changes to the MXML code.

Note: If the result format is e4x, you do not include the root node of the XML structure in the dot notation when binding to the DataGrid.

The XML returned in this example contains no namespace information. For information about working with XML that does contain namespaces,

...
    
...
    

When using the e4x result format, you can optionally bind the lastResult property to an XMLListCollection object and then bind that object to the DataGrid.dataProvider property:

...
    
          
    
...

JSP code

The following example shows the JSP page used in this application. This JSP page does not call a database directly. It gets its data from a Java class called ProductService, which in turn uses a Java class called Product to represent individual products.

<%@page import="flex.samples.product.ProductService, 
                flex.samples.product.Product, 
                java.util.List"%>


<%
    ProductService srv = new ProductService();
    List list = null;
    list = srv.getProducts();
    Product product;
    for (int i=0; i    

<%= product.getName() %>
<%= product.getDescription() %>
<%= product.getPrice() %>
<%= product.getImage() %>
<%= product.getCategory() %>
<%= product.getQtyInStock() %>

<%
    }
%>

Calling HTTP services in ActionScript

The following example shows an HTTP service call in an ActionScript script block. Calling the useHTTPService() method declares the service, sets the destination, sets up result and fault event listeners, and calls the service's send() method.


 

    
        
    
阅读(2225) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-06-25 20:07:54

mx:HTTPService 如何使用代理呢 ? useProxy = "true", 而不直接用 url 来指定