package cs320.servlet; 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("/RequestInfo") public class RequestInfo extends HttpServlet { private static final long serialVersionUID = 1L; public RequestInfo() { super(); } protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { response.setContentType( "text/html" ); PrintWriter out = response.getWriter(); out.println( "" ); out.println( "Display Request Info" ); out.println( "" ); out.println( "Request Method: " + request.getMethod() + "
" ); out.println( "Request URI: " + request.getRequestURI() + "
" ); out.println( "Context Path: " + request.getContextPath() + "
" ); out.println( "You are from: " + request.getRemoteAddr() + "
" ); boolean isGzipSupported = request.getHeader( "Accept-Encoding" ) .indexOf( "gzip" ) >= 0; if( isGzipSupported ) out.println( "Yes, gzip is supported.
" ); else out.println( "No, gzip is not supported.
" ); out.println( "" ); } protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { doGet( request, response ); } }