| 42 | } |
| 43 | |
| 44 | virtual bool doPost(HttpServletRequest& req, HttpServletResponse& res) |
| 45 | { |
| 46 | const char* sid = req.getSession().getAttribute("sid"); |
| 47 | if (*sid == 0) |
| 48 | req.getSession().setAttribute("sid", "xxxxxx"); |
| 49 | sid = req.getSession().getAttribute("sid"); |
| 50 | |
| 51 | const char* cookie1 = req.getCookieValue("name1"); |
| 52 | const char* cookie2 = req.getCookieValue("name2"); |
| 53 | |
| 54 | // ���� HTTP ��Ӧͷ |
| 55 | res.addCookie("name1", "value1"); |
| 56 | res.addCookie("name2", "value2", ".test.com", "/", 3600 * 24); |
| 57 | // res.setStatus(400); // �������÷��ص�״̬�� |
| 58 | |
| 59 | // ���ַ�ʽ�����������ַ��� |
| 60 | if (0) |
| 61 | res.setContentType("text/xml; charset=gb2312"); |
| 62 | else |
| 63 | { |
| 64 | res.setContentType("text/xml"); |
| 65 | res.setCharacterEncoding("gb2312"); |
| 66 | } |
| 67 | |
| 68 | const char* param1 = req.getParameter("name1"); |
| 69 | const char* param2 = req.getParameter("name2"); |
| 70 | |
| 71 | // ���� xml ��ʽ�������� |
| 72 | xml1 body; |
| 73 | body.get_root().add_child("root", true) |
| 74 | .add_child("sessions", true) |
| 75 | .add_child("session", true) |
| 76 | .add_attr("sid", sid ? sid : "null") |
| 77 | .get_parent() |
| 78 | .get_parent() |
| 79 | .add_child("cookies", true) |
| 80 | .add_child("cookie", true) |
| 81 | .add_attr("name1", cookie1 ? cookie1 : "null") |
| 82 | .get_parent() |
| 83 | .add_child("cookie", true) |
| 84 | .add_attr("name2", cookie2 ? cookie2 : "null") |
| 85 | .get_parent() |
| 86 | .get_parent() |
| 87 | .add_child("params", true) |
| 88 | .add_child("param", true) |
| 89 | .add_attr("name1", param1 ? param1 : "null") |
| 90 | .get_parent() |
| 91 | .add_child("param", true) |
| 92 | .add_attr("name2", param2 ? param2 : "null"); |
| 93 | string buf; |
| 94 | body.build_xml(buf); |
| 95 | |
| 96 | // ���� http ��Ӧͷ |
| 97 | if (res.sendHeader() == false) |
| 98 | return false; |
| 99 | // ���� http ��Ӧ�� |
| 100 | if (res.getOutputStream().write(buf) == -1) |
| 101 | return false; |
nothing calls this directly
no test coverage detected