Search code examples
gwtservletsmvp

How to call a servlet from the viewImpl class in GWT?


I'm using GWT 2.4 with the MVP pattern, with uiBinder, and a widget: GwtUploader. When the user selects a file to upload and clicks a button, I need to make a call to a servlet. I'm not calling a service, I just need to access the HttpRequest so I can pull the file that the widget has uploaded, but I'm not clear how to do this?

Here is the uiHandler code:

@UiHandler("loadFileButton")
    void onClickCalculate(ClickEvent e){
        String fileName = fileUploader.getFileName();

        ...

Solution

  • The real answer is you don't. In MVP, the View should defer that kind of behavior to the Presenter, which ideally would defer it to some server-side handler. Check out this answer or this article for examples of how FileUpload can be used for this purpose. Since you mentioned you're using GWTUpload, try reading the Getting Started article.