Saving GWT form data into different application

不羁岁月 提交于 2019-12-25 04:10:22

问题


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:


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



来源:https://stackoverflow.com/questions/16642558/saving-gwt-form-data-into-different-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!