- addTime.mxml:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
- <!--加载页面时到该URL取值放入<mx:DataGrid>中-->
- <mx:Model source="http://localhost:8080/TestServlet/GetTime" id="alltime">
- </mx:Model>
- <mx:Script>
- <![CDATA[
- import mx.rpc.events.ResultEvent;
- import mx.controls.Alert;
- private function check():void{
- var start:String=startTime.text;
- var end:String=endTime.text;
- if(start==null || end==null || start=="" || end==""){
- Alert.show("请填写完整数据","信息提示");
- }else{
- doSumit();
- }
- }
- //点击按钮触发提交事件
- private function doSumit():void{
- submitButton.enabled=false;//按钮置为不可用
- //urlvariables:应用程序和服务器之间传输变量
- var params:urlvariables = new urlvariables();
- //传向的URL 此处的TestServlet/GetTime为我Tomcat下的工程TestServlet,及servlet映射GetTime
- submitTime.url="http://localhost:8080/TestServlet/GetTime";
- //传输方法,经测试默认为get
- submitTime.method="post";
- //params.startTime中的startTime是随意起的名称,后台jsp或servlet可用request.getParameter("startTime");来获取值
- //startTime.text中的startTime是下面的<mx:TextInput>组件的id,其text属性为获取其文本内容
- //<mx:TextInput>相当于<input type="text">
- params.startTime = startTime.text;
- params.endTime = endTime.text;
- submitTime.send(params);//发出发送指令
- }
- //HTTPService处理完提交数据后触发事件,有点类似于aJax的处理数据后对象状态为4时的执行处理
- private function sentEnd(res:ResultEvent):void{
- Alert.show("数据已提交","提示信息");//提示框
- submitButton.enabled=true;//按钮置为可用
- startTime.text="";
- endTime.text="";
- }
- ]]>
- </mx:Script>
- <!--数据通过HTTPService传输-->
- <mx:HTTPService id="submitTime" result="sentEnd(event)"/>
- <mx:Panel width="100%" height="502" layout="absolute" horizontalCenter="5">
- <mx:HBox width="70%" height="8%" borderColor="#84CAFA" themeColor="#3AA7ED" borderStyle="outset" horizontalCenter="20">
- <mx:Label text="设置批次" width="10%" fontSize="14" color="#275C7B"/>
- <mx:Label text="开始时间:" fontSize="11"/>
- <mx:TextInput id="startTime"/>
- <mx:Label text="结束时间:" fontSize="11"/>
- <mx:TextInput id="endTime"/>
- <mx:Button id="submitButton" label="确定" fontSize="11" click="check()"/>
- </mx:HBox>
- <!--绑定DataGrid的数据源dataProvider-->
- <mx:DataGrid dataProvider="{alltime.times}" horizontalCenter="4" verticalCenter="24" width="80%" height="80%" fontSize="11">
- <mx:columns>
- <mx:DataGridColumn headerText="序号" datafield="id"/>
- <mx:DataGridColumn headerText="批次" datafield="time"/>
- <mx:DataGridColumn headerText="操作" datafield="act"/>
- <mx:DataGridColumn headerText="当前批次" datafield="isNow"/>
- </mx:columns>
- </mx:DataGrid>
- </mx:Panel>
- </mx:Module>
- -------------------------------------------------------------------------
- //Servlet :(url)GetTime
- package servlet;
- 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 GetTime extends HttpServlet {
- /**
- * Constructor of the object.
- */
- public GetTime() {
- super();
- }
- /**
- * Destruction of the servlet. <br>
- */
- public void destroy() {
- super.destroy(); // Just puts "destroy" string in log
- // Put your code here
- }
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws servletexception, IOException {
- doPost(request,response);
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws servletexception, IOException {
- response.setContentType("text/html");
- response.setCharacterEncoding("utf-8");
- PrintWriter out = response.getWriter();
- if(request.getParameter("startTime")!=null){
- //接收flex中参数,经不完全测试,只有该转码方式不为乱码
- String startTime = new String(request.getParameter("startTime").getBytes("ISO-8859-1"),"UTF-8");
- String endTime = new String(request.getParameter("endTime").getBytes("ISO-8859-1"),"UTF-8");
- System.out.println(startTime+" *** "+endTime);
- }else{
- /**初始加载flex中addTime.mxml时从本servlet中取出所要在<mx:DataGrid>中显示的数据
- * 目前鄙人只知道能够从xml中获取数据,所以通过servlet做出xml供flex取数据
- * 正式项目时此处可改为从数据库取数据
- **/
- out.println("<?xml version='1.0' encoding='utf-8' ?>");
- out.println("<alltime>");
- out.println("<times>");
- out.println("<id>1</id>");
- out.println("<time>2008-6-24</time>");
- out.println("<act>删除</act>");
- out.println("<isNow>是</isNow>");
- out.println("</times>");
- out.println("<times>");
- out.println("<id>2</id>");
- out.println("<time>2008-5-19</time>");
- out.println("<act>删除</act>");
- out.println("<isNow>否</isNow>");
- out.println("</times>");
- out.println("<times>");
- out.println("<id>3</id>");
- out.println("<time>2008-4-16</time>");
- out.println("<act>删除</act>");
- out.println("<isNow>否</isNow>");
- out.println("</times>");
- out.println("</alltime>");
- out.flush();
- out.close();
- }
- }
- /**
- * Initialization of the servlet. <br>
- *
- * @throws servletexception if an error occurs
- */
- public void init() throws servletexception {
- // Put your code here
- }
- }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。