views:

42

answers:

4

I have the following code...

  @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        final int idValue = Integer.parseInt(req.getParameter("id"));
        final ProjectRunEntity projectRunEntity = projectDataService.findProjectRunEntity(idValue);
        try {
            final byte[] documentAsBytes = wordFileGenerationService.getDocumentAsBytes(projectRunEntity);
            resp.setContentType("application/msword");
            resp.setHeader("Content-Disposition", "inline; filename=example.doc;");
            final ServletOutputStream out = resp.getOutputStream();
            out.write(documentAsBytes);
            out.flush();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

Which gets some bytes which happen to be a word document and write them to the servlet response. For some reason I get the following message in my browser when I hit the url...

"HTTP Status 405 - HTTP method GET is not supported by this URL"

I am on Tomcat 6. Any ideas? I know that nothing is breaking in my debugger, the bytes are being written to the outputstream of the response.

+3  A: 

I guess the error is thrown by the default doGet implementation (when you call super.doGet(req, resp)).

axtavt
+1  A: 

That status is set in super.doGet(...). Please remove that call.

nhnb
+1  A: 

I just had to remove this line...

super.doGet(req, resp);
Benju
+2  A: 

the do{Http-Method} methods are meant to be overridden. And their default implementation is "not supported". No need to call the super.do{http-Method}

naikus