Thanks for your replay, it is good :)
I edit my codes and the app run correctly

the doPost function in the Servlet ::
I get the username and put it in string and return to user by response 
object ::
    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"));
   }

and the code of button event in the project ::
I get username from text field (username) and put the response from the 
Servlet in label (result) ::
 @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);
    }



-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/73073c5e-239b-4b07-8d15-fc5fb797bb1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to