How to send data and redirect to another page using GWT?

When I click the button, I send some data to the server and redirect it to another page. I used RequestBuilder, but it is waiting for a response and, of course, get it. And nothing happens, the same page remains. I see that you should not use RequestBuidler here ... What should I use to publish data and redirect capabilities?

In spring

@RequestMapping(method=RequestMethod.POST, value="/ddd")
public ModelAndView processOrder(@RequestBody String orderInString, HttpSession session) throws Exception{
    ...
    return new ModelAndView(new RedirectView("abc"));

}

In gwt

public void postData(final String data, final String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    try {
        builder.sendRequest(data, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                ...
            }

            public void onResponseReceived(Request request,
                    Response response) {
                if (200 == response.getStatusCode()) {
                    ..
                } else {
                    ..
                }
            }
        });
    } catch (RequestException e) {
        ...
    }
    return;
}
+3
source share
2 answers
    FormPanel form = new FormPanel("_self");
    form.setMethod(FormPanel.METHOD_GET);

    Hidden params0 = new Hidden("param1", "value1");
    Hidden params1 = new Hidden("param1", "value2");
    Hidden params2 = new Hidden("param2", "value3");

    FlowPanel panel = new FlowPanel();
    panel.add(params0);
    panel.add(params1);
    panel.add(params2);

    form.add(panel);

    form.setAction(GWT.getModuleBaseURL() + "../MyServlet");
    RootPanel.get().add(form);
    form.submit();

Here it is. The code adds a FormPanel and submits the form.

+4
source

Add more specs, code, this blur. Since you are using Spring -mvc, you should have something like this

 private static final String newPage = "index2";  //this is resolved with view resolver
 @RequestMapping(params = "action=button")
 protected String getALPLicense(final RenderRequest request,
            final RenderResponse response, final Model model) throws Exception {
 try{
 }catch{
 }
 return newPage;  //this is your new redirected page
 }
0
source

Source: https://habr.com/ru/post/1790900/


All Articles