<mx:HTTPService>给后台传递参数的方法,列举如下:
采用<mx:request/>,

Mxml代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" >
<mx:Model source="http://localhost:8083/webmodule/list?id=123&amp;name=admin" id="model" />

<mx:Panel title="用户信息" width="458" height="332">
<mx:DataGrid dataProvider="{model.user}" width="409" height="231">
<mx:columns>
<mx:DataGridColumn dataField="userid" headerText="ID" width="40" />
<mx:DataGridColumn dataField="username" headerText="用户" />
<mx:DataGridColumn dataField="realname" headerText="姓名" />
<mx:DataGridColumn dataField="adddate" headerText="时间" />
</mx:columns>
</mx:DataGrid>

</mx:Panel>

</mx:Application>



list.java代码:

package com.testflex;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.ResultSet;
import com.testflex.db.SQLServerDB;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;

public class list extends HttpServlet {
private static final String CONTENT_TYPE = "text/xml; charset=utf-8";

//Initialize global variables
public void init() throws ServletException {

}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
//重要:设置响应格式为XML格式
response.setContentType(CONTENT_TYPE);
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String name = request.getParameter("name");
System.out.println("id=" + id);
System.out.println("name=" + name);

PrintWriter out = response.getWriter();
StringBuffer sb = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>").append("\n");
sb.append("<users>").append("\n");

sb.append("<user>").append("\n");
sb.append("<userid>1</userid>").append("\n");
sb.append("<username>1</username>").append("\n");
sb.append("<realname>1</realname>").append("\n");
sb.append("<adddate>1</adddate>").append("\n");
sb.append("</user>").append("\n");

sb.append("<user>").append("\n");
sb.append("<userid>2</userid>").append("\n");
sb.append("<username>2</username>").append("\n");
sb.append("<realname>2</realname>").append("\n");
sb.append("<adddate>2</adddate>").append("\n");
sb.append("</user>").append("\n");

sb.append("<user>").append("\n");
sb.append("<userid>3</userid>").append("\n");
sb.append("<username>3</username>").append("\n");
sb.append("<realname>3</realname>").append("\n");
sb.append("<adddate>3</adddate>").append("\n");
sb.append("</user>").append("\n");

sb.append("</users>").append("\n");
out.println(sb.toString());
out.flush();
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}


創作者介紹

資訊園

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()