From ba5e2b801a4510934f4ac8520a6a689f9d75a192 Mon Sep 17 00:00:00 2001 From: ubuntu14 Date: Wed, 3 Jun 2015 07:59:21 -0700 Subject: [PATCH] modify http_servlet.cpp sample --- .../samples/http/http_servlet/http_servlet.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib_acl_cpp/samples/http/http_servlet/http_servlet.cpp b/lib_acl_cpp/samples/http/http_servlet/http_servlet.cpp index cf8441ae2..85f8e1df4 100644 --- a/lib_acl_cpp/samples/http/http_servlet/http_servlet.cpp +++ b/lib_acl_cpp/samples/http/http_servlet/http_servlet.cpp @@ -35,19 +35,16 @@ bool http_servlet::doGet(acl::HttpServletRequest& req, bool http_servlet::doPost(acl::HttpServletRequest& req, acl::HttpServletResponse& res) { - // 取得 session 数据,如果 session 不存在,则创建 - // 注意: getAttribute 永远返回非空地址,需要根据是否是空串来判断 - // 该 session 的属性是否存在 - acl::string session_name = req.getSession().getAttribute("session_name"); - if (session_name.empty()) + const char* session_name = req.getSession().getAttribute("session_name"); + if (*session_name == 0) { req.getSession().setAttribute("session_name", "name"); req.getSession().setMaxAge(100); } session_name = req.getSession().getAttribute("session_name"); - acl::string session_user = req.getSession().getAttribute("session_user"); - if (session_user.empty()) + const char* session_user = req.getSession().getAttribute("session_user"); + if (*session_user == 0) req.getSession().setAttribute("session_user", "user"); session_user = req.getSession().getAttribute("session_user");