@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {
try {
InfiniteProgress inf = new InfiniteProgress();
Dialog progress = inf.showInifiniteBlocking();
MultipartRequest request = new MultipartRequest();
request.setUrl("http://127.0.0.1:7101/TestServlet-SerlvletTest-context-root/servlet1");
request.setDisposeOnCompletion(progress);
NetworkManager.getInstance().addToQueue(request);
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
//String requestParameter = request.getParameter("type");
response.setContentType(CONTENT_TYPE);
String arrayToJson = "";
arrayToJson = "{\"result\":[" +
"{\"A\":\"The first\"}," +
"{\"B\":\"The second\"}" +
"]}";
response.addHeader("result", arrayToJson);
}
ConnectionRequest req = new ConnectionRequest("http://127.0.0.1:7101/TestServlet-SerlvletTest-context-root/servlet1") {
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
Map<String, Object> parsedData = p.parseJSON(new InputStreamReader(input, "UTF-8"));
... do something with the JSON
}
protected void postResponse() {
... change the UI based on the results of readResponse
}
};
req.setPost(true);
NetworkManager.getInstance().addToQueue(req);
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType(CONTENT_TYPE);
String username = request.getParameter("username");
String json = "";
json = "{\"result\":[" + "{\"username\":\"" + username + "\"}]}";
response.setContentType("application/json; charset=utf-8");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(new String(json.getBytes("utf-8"), "utf-8"));
}
@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {
ConnectionRequest req = new ConnectionRequest("http://127.0.0.1:7101/TestServlet-SerlvletTest-context-root/servlet1") {
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
Map<String, Object> parsedData = p.parseJSON(new InputStreamReader(input, "UTF-8"));
result = parsedData.toString();
}
protected void postResponse() {
//... change the UI based on the results of readResponse
findResult().setText(result);
}
};
req.setPost(true);
req.setDuplicateSupported(true);
req.addArgument("username", findUsername().getText());
req.setTimeout(50000);
NetworkManager.getInstance().addToQueueAndWait(req);
}