0

I hope there are still some GWT developers ... I'm new to GWT development and I'm trying to do a form-based file upload system. To do so, I implemented a HTTPServlet and overrode the methode doPost. However, when I submit the form, I do get a response 200 without any content. But if you look at my file below, I'm sending a 500 response ... And thee System.out.println is not being called ...

I went through a lot of already asked questions on the web but couldn't find a solution ...

POST method not called on servlet - GWT project

servlet not working in GWT

How exactly servlet Work in GWT?

Here are files I have:

web.xml

<servlet>
    <servlet-name>fileupload</servlet-name>
    <servlet-class>com.myCompany.FileUpload
    </servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>fileupload</servlet-name>
    <url-pattern>/myModule/fileupload</url-pattern>
</servlet-mapping>

FormPresenter.java (I'm using MVP Architecture)

formPanel.setAction(GWT.getModuleBaseURL() + "fileupload");
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setMethod(FormPanel.METHOD_POST);

FileUpload.java (Servlet File)

@RemoteServiceRelativePath("fileupload")
public class FileUpload extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("FileUpload doPost");
        resp.sendError(500);
    }
}

Form.ui.xml

<g:FormPanel ui:field="formPanel">
    <g:VerticalPanel>
        <g:FileUpload ui:field="fileUpload"></g:FileUpload>
    </g:VerticalPanel>
</g:FormPanel>

Thanks for your help !

Hyukchan.

Community
  • 1
  • 1
Hyukchan Kwon
  • 382
  • 1
  • 5
  • 20

2 Answers2

0

Remove @RemoteServiceRelativePath("fileupload"). You already set your mapping in web.xml.

Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
0

Oh I actually found the problem in my code ... I had a filter defined with a general url pattern

web.xml

<filter-mapping>
    <filter-name>myFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

which was called before my servlet and I forgot to use :

MyFilter.java

chain.doFilter(request, response);

to call the rest of filters and servlet...

Thanks for your help though Andrei !

Hyukchan Kwon
  • 382
  • 1
  • 5
  • 20