flex3 Grid获取jsp数据的简单应用

很多时候我们需要在jsp展现数据用的都是table,来看看
用flex3的Grid怎么做。

测试数据:

  if   object_id ( ' product ' is   not   null  
   
drop   table  product

create   table  product
(
  id 
int   primary   key   identity ( 1 , 1 ),
  productName 
varchar ( 50 ),
  remark 
varchar ( 100 )
)

declare   @i   int
set   @i   =   1
while   @i   <   100
begin
   
insert   into  product  values ( ' 产品 '   +   convert ( varchar ( 3 ), @i ), ' 备注 '   +   convert ( varchar ( 3 ), @i ))
   
set   @i   =   @i   +   1
end


select   *   from  product

grid需要的是xml数据源:
<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  creationComplete ="list.send()" >
    
<!-- jsp请求 -->
    
<!-- <mx:HTTPService id="list" url="../index.jsp" /> -->
    
<!-- Servlet请求 -->
    
< mx:HTTPService  id ="list"  url ="../productServlet"   />
    
<!-- grid数据绑定 -->
    
< mx:DataGrid  dataProvider ="{list.lastResult.catalog.product}"   width ="395"  height ="307"  x ="223"  y ="54"  color ="#F2C50F" ></ mx:DataGrid >
</ mx:Application >

看一提供数据的Servlet:
package  com;

import  java.io.IOException;
import  java.io.PrintWriter;
import  java.util.List;

import  javax.servlet.ServletException;
import  javax.servlet.http.HttpServlet;
import  javax.servlet.http.HttpServletRequest;
import  javax.servlet.http.HttpServletResponse;

import  com.dao.ProductDao;
import  com.vo.Product;

@SuppressWarnings(
" serial " )
public   class  ProductServlet  extends  HttpServlet
{
    
public void doGet(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException
    
{

        response.setContentType(
"text/html");
        response.setCharacterEncoding(
"utf-8");
        PrintWriter out 
= response.getWriter();
        String str 
= "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
        str 
+= "<catalog>";
        ProductDao srv 
= new ProductDao();
        List
<Product> list = null;
        list 
= srv.getAll();
        Product product;
        
for (int i = 0; i < list.size(); i++)
        
{
            product 
= (Product) list.get(i);
            str 
+= "<product productId=\"" + product.getId() + "\">";
            str 
+= "<productName>" + product.getProductName() + "</productName>";
            str 
+=     "<remark>" + product.getRemark() +"</remark>";
            str 
+= "</product>";
        }

        str 
+= "</catalog>";
        out.write(str);
        
    }


    
public void doPost(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException
    
{
        
this.doGet(request, response);
    }


}

当然你也可以写成jsp的形式:
<% @ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% @page import="com.dao.ProductDao" %>
<% @page import="com.vo.Product" %>

<? xml version="1.0" encoding="utf-8" ?>
< catalog >
<%
    ProductDao srv 
= new ProductDao();
    List
<Product> list = null;
    list 
= srv.getAll();
    Product product;
    
for (int i = 0; i < list.size(); i++)
    {
        product 
= (Product) list.get(i);
%>
< product  productId ="<%=product.getId()%>" >
    
< productName > <% = product.getProductName() %> </ productName >
    
< remark > <% = product.getRemark() %> </ remark >
</ product >
<%
    }
%> </ catalog >

HTTPService标签实例化一个对象它将会请求jsp和反序列化请求对象。url属性需要指定jsp或Servlet Action并且返回xml数据。其中list是HTTPService标签的id,lastResult属性包含了一个对象叫"catalog",相当于xml的catalog节点。在catalog节点下有节点数组product.这个list.lastResult.catalog.product相当于从HTTPService请求jsp返回的数组。

 如图:


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值