Saving GWT form data into different application

2019-08-28 01:07发布

I have a GWT application which has form. If user enters data and submit i have to store the data into google datastore and also an JSP application which is running on tomcat server. I found this is done through Task in GAE GAE Push Task from this i am calling a servlet in my gwt application and in that servlet URL fetch There i have to code to send data to another application and call the servlet to insert data. Can anyone give me how to do it(By a simple example). Is this a correct approach or any other way to do this correctly?

1条回答
劫难
2楼-- · 2019-08-28 01:33

I have done it successfully added a push queue task in server side and called a servlet from there which is registered in guice. then in that servlet i called the fallowing lines

Task queue code

Queue queue = QueueFactory.getDefaultQueue();
            queue.addAsync(TaskOptions.Builder.withUrl("/userServlet").method(Method.GET).param("userName", userName).param("pwd", pwd).param("mail",mail));

and userservlet has fallowing code to connect to theother application

final String url_Name = "http://xxxxxxxx.com/AddUserServlet";

         //final String url_Name = "http://localhost:8181/jos-webapp-1.2.1/AddUserServlet";

         URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
         HTTPRequest request = null;
         HTTPResponse response= null;
         try{


             URL url = new URL(url_Name);

             request = new HTTPRequest(url, HTTPMethod.POST);

             String body = "userName="+uName+"&pwd="+pwd+"email"+email;
             request.setPayload(body.getBytes());

             response = fetcher.fetch(request);

         }catch(Exception ex){
             ex.printStackTrace();
         }

In my JOIDS(second application) I wrote a servlet(AdduserServlet) and used someget the data. Any better solution than this will be accepted

查看更多
登录 后发表回答