MyRequestProcessor.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package test;
  2. import java.util.Enumeration;
  3. import javax.servlet.http.Cookie;
  4. import javax.servlet.http.HttpServlet;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.apache.struts.action.RequestProcessor;
  8. public class MyRequestProcessor extends RequestProcessor {
  9. public MyRequestProcessor() {}
  10. public boolean processPreprocess(HttpServletRequest request,
  11. HttpServletResponse response) {
  12. log("-------------- My Logging Start--------------");
  13. log("Request URI = " + request.getRequestURI());
  14. log("Context Path = " + request.getContextPath());
  15. Cookie cookies[] = request.getCookies();
  16. if (cookies != null) {
  17. log("Cookies:");
  18. for (int i = 0; i < cookies.length; i++) {
  19. log(cookies[i].getName() 
  20. + " = " + cookies[i].getValue());
  21. }
  22. }
  23. Enumeration headerNames = request.getHeaderNames();
  24. log("Request Header:");
  25. while (headerNames.hasMoreElements()) {
  26. String headerName = 
  27. (String)headerNames.nextElement();
  28. Enumeration headerValues = 
  29. request.getHeaders(headerName);
  30. while (headerValues.hasMoreElements()) {
  31. String headerValue = 
  32. (String)headerValues.nextElement();
  33. log("    " + headerName + " = " + headerValue);
  34. }
  35. }
  36. log("Locale = " + request.getLocale());
  37. log("Method = " + request.getMethod());
  38. log("Path Info = " + request.getPathInfo());
  39. log("Protocol = " + request.getProtocol());
  40. log("Remote Address = " + request.getRemoteAddr());
  41. log("Remote Host = " + request.getRemoteHost());
  42. log("Remote User = " + request.getRemoteUser());
  43. log("Requested Session Id = " 
  44. + request.getRequestedSessionId());
  45. log("Scheme = " + request.getScheme());
  46. log("Server Name = " + request.getServerName());
  47. log("Server Port = " + request.getServerPort());
  48. log("Servlet Path = " + request.getServletPath());
  49. log("Secure = " + request.isSecure());
  50. log("-------------- My Logging End  --------------");
  51. return true;
  52. }
  53. }