Tuesday, 5 August 2014

isAsyncSupported() : Checks for Asynchronous mode support

public boolean isAsyncSupported()
Returns true if this request supports asynchronous operation, else false.

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/ProcessRequest"}, asyncSupported=true)
public class ProcessRequest extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{
      try(PrintWriter out = res.getWriter()){
          out.println("<html><head><title>Asynch Mode</title></head>");
          out.println("<body><h1>");
          out.println("Is Asynchronous mode supported " + req.isAsyncSupported());
          out.println("</h1></body></html>");
      } 
    }
}

Run the servlet like below.


Output


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/ProcessRequest"})
public class ProcessRequest extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{
      try(PrintWriter out = res.getWriter()){
          out.println("<html><head><title>Asynch Mode</title></head>");
          out.println("<body><h1>");
          out.println("Is Asynchronous mode supported " + req.isAsyncSupported());
          out.println("</h1></body></html>");
      } 
    }
}

Output






Prevoius                                                 Next                                                 Home

No comments:

Post a Comment