本文整理匯總了Java中javax.servlet.ServletOutputStream.setWriteListener方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletOutputStream.setWriteListener方法的具體用法?Java ServletOutputStream.setWriteListener怎麽用?Java ServletOutputStream.setWriteListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.ServletOutputStream
的用法示例。
在下文中一共展示了ServletOutputStream.setWriteListener方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOutputStream
import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@Override
public ServletOutputStream getOutputStream() throws IOException {
final ServletOutputStream outputStream = d.getOutputStream();
return new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
respBody.write(b);
outputStream.write(b);
}
@Override
public void setWriteListener(WriteListener writeListener) {
outputStream.setWriteListener(writeListener);
}
@Override
public boolean isReady() {
return outputStream.isReady();
}
};
}
示例2: processRequest
import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
AsyncContext context = request.startAsync();
ServletOutputStream output = response.getOutputStream();
output.setWriteListener(new WritingListener(output, context));
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:9,代碼來源:WritingServlet.java
示例3: handle
import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@Override
public void handle(String path, Request request, final HttpServletRequest servletRequest,
final HttpServletResponse servletResponse) throws IOException, ServletException {
request.setHandled(true);
switch (path) {
case "/hello":
servletResponse.setStatus(200);
servletResponse.setContentType("text/plain");
servletResponse.getWriter().write("Hello World!");
break;
case "/hello-async":
final AsyncContext context = request.startAsync();
Thread t = new Thread(() -> {
servletResponse.setStatus(200);
servletResponse.setContentType("text/plain");
final ServletOutputStream outputStream;
try {
outputStream = servletResponse.getOutputStream();
outputStream.setWriteListener(new WriteListener() {
@Override
public void onWritePossible() throws IOException {
PrintWriter w = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8"));
w.write("Hello World!");
w.close();
context.complete();
}
@Override
public void onError(Throwable throwable) {
context.complete();
}
});
} catch (IOException e) {
context.complete();
}
});
t.start();
break;
default:
servletResponse.setStatus(404);
servletResponse.setContentType("text/plain");
servletResponse.getWriter().write("Not found.");
break;
}
}