flex调用servlet连接数据库

flex调用servlet连接数据库

ID:22978645

大小:103.50 KB

页数:13页

时间:2018-11-02

flex调用servlet连接数据库_第1页
flex调用servlet连接数据库_第2页
flex调用servlet连接数据库_第3页
flex调用servlet连接数据库_第4页
flex调用servlet连接数据库_第5页
资源描述:

《flex调用servlet连接数据库》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、FLex调用servlet连接数据库前言Flex最重要的部分之一就是和服务器以及数据库的通讯。Flex提供了三个类来与服务器通讯:HTTPService,RemoteObject以及WebService。HTTPService类提供了使用超文本传输协议(HTTP)与服务器通讯的方式。一个Flex应用程序可以使用GET或者POST请求来发送数据到一个服务器并且处理这个请求返回的XML或者字符串。使用HTTPService类,你可以与PHP页面,ColdFusion页面,JavaServe页面(jsp),Javas

2、ervlet,RubyonRails,以及ASP动态网页通讯。与JavaServlet通讯由于本人是Java出身,所以这里就来讨论一下与Servlet的通讯方式。建立数据库这里选用MySql数据库,首先建立如下的数据库表写服务器端Java代码Servletviewplaincopytoclipboardprint?packageservlet;importjava.io.IOException;importjava.io.PrintWriter;importjava.util.List;importjavax.

3、servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importPODO.Product;importdb.ProductDao;publicclassGetProductServletextendsHttpServlet{Listresult;/***Constr

4、uctoroftheobject.*/publicGetProductServlet(){super();}/***Destructionoftheservlet.
*/publicvoiddestroy(){super.destroy();//Justputs"destroy"stringinlog//Putyourcodehere}/***ThedoGetmethodoftheservlet.
**Thismethodiscalledwhenaformhasitstagvaluemethodeq

5、ualstoget.**@paramrequest*therequestsendbytheclienttotheserver*@paramresponse*theresponsesendbytheservertotheclient*@throwsServletException*ifanerroroccurred*@throwsIOException*ifanerroroccurred*/publicvoiddoGet(HttpServletRequestrequest,HttpServletResponser

6、esponse)throwsServletException,IOException{result=newProductDao().getProduct();StringxmlContent="";response.setContentType("text/xml;charset=utf-8");PrintWriterout=response.getWriter();if(result!=null){for(inti=0

7、;i"+p.getName()+""+p.getType()+""+p.getPrice()+""+p.getNum()+"";}xmlContent+="";out.print(xmlContent);out.flush

8、();out.close();}}/***ThedoPostmethodoftheservlet.
**Thismethodiscalledwhenaformhasitstagvaluemethodequalsto*post.**@paramrequest*therequestsendbytheclienttotheserver*@paramresponse*therespons

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。