ユーザーから入力文字列を正常に受信し、サーバー側で処理して、結果をWebページに表示するアプリケーションがあります。これをRemoteServiceServletとして実装しました。これにより、すべてのWebサイトガジェットを簡単に処理できるようになりました。
それでも、結果をWebページに表示する代わりに、「コンテンツ処理添付ファイル」の可能性を使用して、ユーザーが処理された文字列を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"
}
});