ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 测试

测试

原创 Linux操作系统 作者:it01 时间:2019-01-29 10:27:07 0 删除 编辑

1.测试类
我写了一个RequestInfoServlet,可以显示HttpRequest的绝大部分有用信息,经过sso后,可以查看 HttpRequest里面还有什么东西。呵呵,我喜欢这样干。

代码
  1. import java.io.IOException;
  2. import java.io.PrintWriter;
  3. import java.util.Enumeration;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.http.Cookie;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import javax.servlet.http.HttpSession;
  10. /**
  11. * @author Liujj Date 2006-12-19 <br>
  12. * Description: <br>
  13. * RequestHeadersServlet
  14. */
  15. public class RequestInfoServlet extends HttpServlet {
  16. public void doGet(HttpServletRequest request, HttpServletResponse response)
  17. throws IOException, ServletException {
  18. response.setContentType("text/html");
  19. PrintWriter out = response.getWriter();
  20. //header
  21. Enumeration headerNames = request.getHeaderNames();
  22. out.println("<B>*********[1].begin print headerNames************B><p>");
  23. while (headerNames.hasMoreElements()) {
  24. String name = (String) headerNames.nextElement();
  25. String value = request.getHeader(name);
  26. out.println(name + " = " + value + "<p>");
  27. }
  28. out.println("<B>*********[1].end print headerNames************B><p><p>");
  29. //attributeNames
  30. out.println("<B>*********[2].begin print attributeNames************B><p>");
  31. Enumeration attributeNames = request.getAttributeNames();
  32. while (attributeNames.hasMoreElements()) {
  33. String name = (String) attributeNames.nextElement();
  34. String value = (String)request.getAttribute(name);
  35. out.println(name + " = " + value + "<p>");
  36. }
  37. out.println("<B>*********[2].end print attributeNames************B><p><p>");
  38. //parameterNames
  39. out.println("<B>*********[3].begin print parameterNames************B><p>");
  40. Enumeration parameterNames = request.getParameterNames();
  41. while (parameterNames.hasMoreElements()) {
  42. String name = (String) parameterNames.nextElement();
  43. String value = request.getParameter(name);
  44. out.println(name + " = " + value + "<p>");
  45. }
  46. out.println("<B>*********[3].end print parameterNames************B><p><p>");
  47. //session
  48. out.println("<B>*********[4].begin print session AttributeNames************B><p>");
  49. HttpSession session = request.getSession();
  50. Enumeration sAttributeNames = session.getAttributeNames();
  51. while (sAttributeNames.hasMoreElements()) {
  52. String name = (String) sAttributeNames.nextElement();
  53. Object value = session.getAttribute(name);
  54. out.println(name + " = " + value + "<p>");
  55. }
  56. out.println("<B>*********[4].end print session attributeNames************B><p><p>");
  57. //cookie
  58. out.println("<B>*********[4].begin print Cookie************B><p><p>");
  59. Cookie[] cookie = request.getCookies();
  60. for(int i=0; i< cookie.length; i++) {
  61. String name = cookie[i].getName();
  62. String value = cookie[i].getValue();
  63. out.println(name + " = " + value + "<p>");
  64. }
  65. out.println("<B>*********[4].end print Cookie************B><p><p>");
  66. }
  67. }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12467/viewspace-148202/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2002-05-25

  • 博文量
    380
  • 访问量
    283328