ユーザーからの入力文字列を正常に受信し、サーバー側で処理し、その結果をWebページに表示するアプリケーションがあります。私はこれをRemoteServiceServletとして実装しました。この方法ですべてのウェブサイトガジェットを簡単に処理できるからです。RemoteServiceServletでコンテンツ処理アタッチメントを使用する
ウェブページに結果を表示する代わりに、ユーザーが処理された文字列をtxtファイルにダウンロードできるように、「コンテンツ処理添付ファイル」の可能性を使用することにしました。
アプリケーション全体をRemoteServiceServletからHttpServletに変更せずにこれを行う方法はありますか?
以下、私のコードです。感謝万円。
ProjectServiceImpl.java
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;
}
}
ProjectService.java
public interface ProjectService extends RemoteService {
String project(String name) throws IllegalArgumentException;
}
ProjectServiceAsync.java
public interface ProjectServiceAsync {
void project(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
}
MyProject.java:クライアント側
[...]
projectService.project(originalString, new AsyncCallback<String>() {
[...]
public void onSuccess(final String result)
{
[...] // Or perhaps should I create here in client-side the txt file with "result"
}
});