`
pipe
  • 浏览: 205251 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

flex与servlet交互

    博客分类:
  • flex
阅读更多
首先,我们在eclipse中创建一个web project  取名为simple

在这个project中我们创建一个servlet:代码如下:

package com.test;

import java.io.IOException;
import java.io.PrintWriter;

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

public class TestServlet extends HttpServlet {

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

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		out.println("<rss>");
		out.println("<xml>");
			out.println("<pubDate>pubDate11111</pubDate>");
			out.println("<title>title111</title>");
			out.println("<description>description111</description>");
		out.println("</xml>");
		out.println("<xml>");
			out.println("<pubDate>pubDate222</pubDate>");
			out.println("<title>title22</title>");
			out.println("<description>description122211</description>");
	out.println("</xml>");
	out.println("</rss>");
	}

}

这个servlet的访问地址为:http://localhost:8080/simple/test,
现在我们在flex buider3中创建一个flex project,选择web root为tomcat/webapps下面, 取名test.
新建一个connect.mxml文件 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="feedRequest.send()">
	<mx:HTTPService id="feedRequest" url="http://localhost:8080/simple/test"
		useProxy="false">
		
	</mx:HTTPService>
	<mx:Panel x="10" y="10" width="800" height="400" layout="absolute" horizontalAlign="right"
		>
		<mx:DataGrid x="20" y="20" id="dgPosts" width="400" verticalCenter="center" dataProvider="{feedRequest.lastResult.rss.xml}">
			<mx:columns>
				<mx:DataGridColumn headerText="标题" dataField="title" />
				<mx:DataGridColumn headerText="时间" dataField="pubDate"/>
			
			</mx:columns>
		</mx:DataGrid>
		<mx:TextArea x="20" y="175" width="400" height="100" htmlText="{dgPosts.selectedItem.description}"/>
		
	</mx:Panel>
	
	
</mx:Application>


好了!访问一下:http://localhost:8080/test/bin-debug/connect.html
截图如下:

  • 大小: 1.2 MB
分享到:
评论
4 楼 zdlly617 2011-08-03  
如何把你的这篇博客转到我的博客中呀,我只能收藏你的这篇博客,这样的话,如果收藏的日志多了的话,就不好管理。我在博客中建立了几个分类,但是就是不知道怎么把收藏的日志分到对应的分类中,就像你的博客遮掩分类显示。
3 楼 tianhaos 2011-01-26  
哪位大侠能指点一下,我做flex与servlet交互时,报 “-由于“HTTPService”声明未实现“mx.core.IUIComponent”,它必须包含在 <Declarations> 标签中。” 错误,郁闷啊!!
2 楼 lxtkong-029 2009-11-21  
楼主:feedRequest.lastResult.rss.xml应改为:feedRequest.lastResult.xml
1 楼 wei83523408 2009-08-20  
楼主,问一下,你的那个flex project选择的Application server Type选择的什么啊。怎么我没找到Web root .我用的是插件版的FB3,难道两者不同吗?麻烦楼主把步骤弄详细点,刚学,不太懂。谢谢

相关推荐

Global site tag (gtag.js) - Google Analytics