Skip to content

Instantly share code, notes, and snippets.

@subchen
Created February 21, 2014 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subchen/9128267 to your computer and use it in GitHub Desktop.
Save subchen/9128267 to your computer and use it in GitHub Desktop.
request_dump.jsp
<%@page contentType="text/html" pageEncoding="utf-8" trimDirectiveWhitespaces="true" %>
<%@page import="java.util.*" %>
<%@page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>samples</title>
</head>
<body>
<pre><xml>
<%!
String FORMAT = "%20s: %s%n";
PrintWriter os = new PrintWriter(out);
os.println("Request Basic: ");
os.printf(FORMAT, "ContextPath", request.getContextPath());
os.printf(FORMAT, "PathInfo", request.getPathInfo());
os.printf(FORMAT, "ServletPath", request.getServletPath());
os.printf(FORMAT, "Request URI", request.getRequestURI());
os.printf(FORMAT, "Request URL", request.getRequestURL());
os.printf(FORMAT, "QueryString", request.getQueryString());
os.printf(FORMAT, "Method", request.getMethod());
os.println();
os.printf(FORMAT, "CharacterEncoding", request.getCharacterEncoding());
os.printf(FORMAT, "ContentType", request.getContentType());
os.printf(FORMAT, "ContentLength", request.getContentLength());
os.printf(FORMAT, "Locale", request.getLocale());
os.printf(FORMAT, "RemoteAddr", request.getRemoteAddr());
os.println();
os.println("Request Headers:");
Enumeration<String> header = request.getHeaderNames();
while (header.hasMoreElements()) {
String name = header.nextElement();
String value = request.getHeader(name);
os.printf(FORMAT, name, value);
}
os.println();
os.println("Request Parameters:");
Enumeration<String> param = request.getParameterNames();
while (param.hasMoreElements()) {
String name = param.nextElement();
String value[] = request.getParameterValues(name);
os.printf(FORMAT, name, StringUtils.join(value, ", "));
}
os.println();
os.println("Request Cookies:");
for (Cookie cookie : request.getCookies()) {
os.printf(FORMAT, cookie.getName(), cookie.getValue());
}
os.println();
os.flush();
}
%>
</xml></pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment