title: Use content-disposition attachment in RemoteServiceServlet
body: <p>I have an application that successfully receives an input string from the user, processes it on server-side, and displays the result on a webpage. I had implemented it as a RemoteServiceServlet, because this way I can handle all the website gadgets easily.</p>
  
  <p>Nevertheless I have decided to, instead of displaying the result on a webpage, use the "content-disposition attachment" possibilities so that the user can download the processed string in a txt file.</p>
  
  <p>Is there a way to do this without changing the whole application from RemoteServiceServlet to HttpServlet?</p>
  
  <p>Below my code. Thanks a million.</p>
  
  <p><strong>ProjectServiceImpl.java</strong></p>
  
  <pre><code>public class ProjectServiceImpl extends RemoteServiceServlet implements ProjectService 
  {
      public String project(String input) throws IllegalArgumentException 
      {
          String output = processString(input);
          // Below something I tried to do, but it does not work at all
          try {
              HttpServletResponse resp = getThreadLocalResponse();
          resp.reset();
          resp.setContentType("application/octet-stream");
          resp.setContentLength(10);
          resp.setHeader("Content-disposition", "attachment; filename=\"test.txt\"");
          ServletOutputStream op = resp.getOutputStream();
          op.write(convertToByteArray(output),0,10);
          op.flush();
          op.close();
          }
          catch (IOException e) {
              e.printStackTrace();
          }
          return output;
      }
  }
  </code></pre>
  
  <p><strong>ProjectService.java</strong></p>
  
  <pre><code>public interface ProjectService extends RemoteService {
      String project(String name) throws IllegalArgumentException;
  }
  </code></pre>
  
  <p><strong>ProjectServiceAsync.java</strong></p>
  
  <pre><code>public interface ProjectServiceAsync {
      void project(String input, AsyncCallback&lt;String&gt; callback)
              throws IllegalArgumentException;
  }
  </code></pre>
  
  <p><strong>MyProject.java: Client side</strong></p>
  
  <pre><code>[...]
  projectService.project(originalString, new AsyncCallback&lt;String&gt;() {
      [...]
      public void onSuccess(final String result) 
      {
          [...] // Or perhaps should I create here in client-side the txt file with "result"
      }
  });
  </code></pre>