当前位置: 首页>>代码示例>>C++>>正文


C++ HttpServletResponse类代码示例

本文整理汇总了C++中HttpServletResponse的典型用法代码示例。如果您正苦于以下问题:C++ HttpServletResponse类的具体用法?C++ HttpServletResponse怎么用?C++ HttpServletResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HttpServletResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doGet

    void doGet(HttpServletRequest& req, HttpServletResponse &res) {
        res.setContentType("text/plain");
        ostream& out = res.getOutputStream();
        out << "pid: " << getpid() << endl << endl;

        string action = req.getParameter("action");
        if(action == "list") {
            servlet::loader& loader = servlet::loader::instance();
            out << "Loaded servlets(" << loader.pool.size() << "):" << endl;
            int cnt = 0;
            char timebuf[256];
            for(std::map<std::string, servlet::loader::pool_entry>::const_iterator i = loader.pool.begin();
                i != loader.pool.end(); ++i)
            {
                apr_rfc822_date(timebuf, i->second.atime);
                HttpServlet* servlet = i->second.servlet;
                out << ++cnt << ": " << (servlet ? typeid(*servlet).name() : "NULL") <<
                    "\t(Access: " << timebuf << ", Load: ";
                apr_rfc822_date(timebuf, i->second.ltime);
                out << timebuf << ")" << endl;
            }
        }else if(action == "load") {
            string path = req.getParameter("path");
            servlet::loader::instance().load(path);
            out << "Loaded " << path << endl;
        }else {
            out << "Unknown action: " << action << endl;
        }
    }
开发者ID:rzymek,项目名称:cxxsp,代码行数:29,代码来源:Manager.cpp

示例2: doGet

void RefreshTestServlet::doGet(HttpServletRequest& req, HttpServletResponse& resp)
{
	Timestamp now;
	std::string dt(DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT));
	Timespan ts(_started.elapsed());

	resp.setHeader("Transfer-Encoding", "chunked");
	resp.setContentType("text/html");

	resp.getOutputStream() 
		<< "<html><head><title>Poco Servlet Engine Test</title>"
		<< "<meta http-equiv=\"refresh\" content=\"1\"></head>"
		<< "<body>"
		<< "<p style=\"text-align: center; font-size: 48px;\">Current UTC time: "
		<< dt
		<< "</p>"
		<< "<p style=\"text-align: center; font-size: 48px;\">Elapsed: "
		<< std::setw(2) << std::setfill('0') << ts.hours() << ':' 
		<< std::setw(2) << std::setfill('0') << ts.minutes() << ':' 
		<< std::setw(2) << std::setfill('0') << ts.seconds()
		<< "</p>"
		<< "<p style=\"text-align: center; font-size: 48px;\">Hit Count: "
		<< ++_hitCounter
		<< "</p>"
		<< "</body></html>";
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:26,代码来源:TestServlet.cpp

示例3: doPost

	// POST 方法
	virtual bool doPost(HttpServletRequest& req, HttpServletResponse& res)
	{
		// 如果 session 项不存在,则设置
#if 0
		const char* sid = req.getSession().getAttribute("sid");
		if (*sid == 0)
			req.getSession().setAttribute("sid", "xxxxxx");
#endif

		// 创建 HTTP 响应头
                res.addCookie("name1", "value1");
		res.addCookie("name2", "value2", ".test.com", "/", 3600 * 24);
//		res.setStatus(400);  // 可以设置返回的状态码

		// 两种方式都可以设置字符集
		if (0)
			res.setContentType("text/xml; charset=gb2312");
		else
		{
			res.setContentType("text/xml");
			res.setCharacterEncoding("gb2312");
		}

		// 获得 HTTP 请求的数据类型,正常的参数类型,即 name&value 方式
		// 还是 MIME 数据类型,还是数据流类型
		http_request_t request_type = req.getRequestType();
		if (request_type == HTTP_REQUEST_NORMAL)
			return doParams(req, res);
		else if (request_type == HTTP_REQUEST_MULTIPART_FORM)
			return doUpload(req, res);
		assert(request_type == HTTP_REQUEST_OCTET_STREAM);
		return doOctetStream(req, res);
	}
开发者ID:2202877,项目名称:acl,代码行数:34,代码来源:main.cpp

示例4: doResponse

	bool doResponse(HttpServletRequest& req, HttpServletResponse& res)
	{
		// 获得浏览器传来的 cookie 值
		const char* cookie1 = req.getCookieValue("name1");
		const char* cookie2 = req.getCookieValue("name2");

		// 获得 sid session 值
		const char* sid = req.getSession().getAttribute("sid");

		// 创建 xml 格式的数据体
		xml body;
		body.get_root().add_child("root", true)
			.add_child("content_type", true)
				.add_attr("type", (int) req.getRequestType())
				.get_parent()
			.add_child("sessions", true)
				.add_child("session", true)
					.add_attr("sid", sid ? sid : "null")
					.get_parent()
				.get_parent()
			.add_child("cookies", true)
				.add_child("cookie", true)
					.add_attr("name1", cookie1 ? cookie1 : "null")
					.get_parent()
				.add_child("cookie", true)
					.add_attr("name2", cookie2 ? cookie2 : "null")
					.get_parent()
				.get_parent()
			.add_child("params", true)
				.add_child("param", true)
					.add_attr("name1", param1_ ? param1_ : "null")
					.get_parent()
				.add_child("param", true)
					.add_attr("name2", param2_ ? param2_ : "null")
					.get_parent()
				.add_child("param", true)
					.add_attr("name3", param3_ ? param3_ : "null")
					.get_parent()
				.get_parent()
			.add_child("files", true)
				.add_child("file", true)
					.add_attr("filename", file1_ ? file1_ : "null")
					.get_parent()
				.add_child("file", true)
					.add_attr("filename", file2_ ? file2_ : "null")
					.get_parent()
				.add_child("file", true)
					.add_attr("filename", file3_ ? file3_ : "null");
		string buf;
		body.build_xml(buf);

		// 发送 http 响应头
		if (res.sendHeader() == false)
			return false;
		// 发送 http 响应体
		if (res.getOutputStream().write(buf) == -1)
			return false;
		return true;
	}
开发者ID:aaronshang,项目名称:acl,代码行数:59,代码来源:main.cpp

示例5: MaybeSetLastModified

/*
 * Sets the Last-Modified entity header field, if it has not
 * already been set and if the value is meaningful.  Called before
 * DoGet, to ensure that headers are set before response data is
 * written. A subclass might have set this header already, so we
 * check.
 */
static void MaybeSetLastModified(HttpServletResponse& resp,
                                 long long lastModified)
{
  if (resp.ContainsHeader(HEADER_LASTMOD))
    return;
  if (lastModified >= 0)
    resp.SetDateHeader(HEADER_LASTMOD, lastModified);
}
开发者ID:CppMicroServices,项目名称:CppMicroServices,代码行数:15,代码来源:HttpServlet.cpp

示例6: doResponse

	bool doResponse(HttpServletRequest& req, HttpServletResponse& res)
	{
		// 获得浏览器传来的 cookie 值
		const char* cookie1 = req.getCookieValue("name1");
		const char* cookie2 = req.getCookieValue("name2");

		// 创建 xml 格式的数据体
		xml body;
		body.get_root().add_child("root", true)
			.add_child("content_type", true)
				.add_attr("type", (int) req.getRequestType())
				.get_parent()
			.add_child("cookies", true)
				.add_child("cookie", true)
					.add_attr("name1", cookie1 ? cookie1 : "null")
					.get_parent()
				.add_child("cookie", true)
					.add_attr("name2", cookie2 ? cookie2 : "null")
					.get_parent()
				.get_parent()
			.add_child("params", true)
				.add_child("param", true)
					.add_attr("name1", param1_ ? param1_ : "null")
					.get_parent()
				.add_child("param", true)
					.add_attr("name2", param2_ ? param2_ : "null")
					.get_parent()
				.add_child("param", true)
					.add_attr("name3", param3_ ? param3_ : "null")
					.get_parent()
				.get_parent()
			.add_child("files", true)
				.add_child("file", true)
					.add_attr("filename", file1_ ? file1_ : "null")
					.get_parent()
				.add_child("file", true)
					.add_attr("filename", file2_ ? file2_ : "null")
					.get_parent()
				.add_child("file", true)
					.add_attr("filename", file3_ ? file3_ : "null");
		string buf("<?xml version=\"1.0\"?>");
		body.build_xml(buf);

		//printf(">>>response: %s\r\n", buf.c_str());
		//res.setContentLength(buf.length());

		// 不必显示工调用下面过程来发送 http 响应头
		//if (res.sendHeader() == false)
		//	return false;
		// 发送 http 响应体,当使用 chunk 传输时,必须最后调用一次发送空数据
		if (res.write(buf) == false || res.write(NULL, 0) == false)
			return false;
		return true;
	}
开发者ID:10jschen,项目名称:acl,代码行数:54,代码来源:ssl_server.cpp

示例7: DoPut

void HttpServlet::DoPut(HttpServletRequest& request, HttpServletResponse& response)
{
  std::string protocol = request.GetProtocol();
  std::string msg = "Http PUT method not supported";
  if (protocol.size() > 2 && protocol.substr(protocol.size()-3) == "1.1")
  {
    response.SendError(HttpServletResponse::SC_METHOD_NOT_ALLOWED, msg);
  }
  else
  {
    response.SendError(HttpServletResponse::SC_BAD_REQUEST, msg);
  }
}
开发者ID:CppMicroServices,项目名称:CppMicroServices,代码行数:13,代码来源:HttpServlet.cpp

示例8: doOther

	virtual bool doOther(HttpServletRequest&, HttpServletResponse& res,
		const char* method)
	{
		res.setStatus(400);
		res.setContentType("text/xml; charset=gb2312");
		// 发送 http 响应头
		if (res.sendHeader() == false)
			return false;
		// 发送 http 响应体
		string buf;
		buf.format("<root error='unkown method: %s' />\r\n", method);
		(void) res.getOutputStream().write(buf);
		return false;
	}
开发者ID:nitsel88,项目名称:acl,代码行数:14,代码来源:http_servlet.cpp

示例9: doGet

 void doGet(HttpServletRequest& request, HttpServletResponse &response) {
     response.setContentType("text/html");
     ostream& out = response.getOutputStream();
     out << "<html><body>" << endl;
     HttpSession* session = request.getSession();
     if(session->hasAttribute("lastVisit")) {
         time_t lastVisit = session->getAttribute<time_t>("lastVisit");
         out << "Witaj ponownie. Pierwszy raz odwiedziles nas: <br>"
             << ctime(&lastVisit) << endl;
     }else{
         out << "Witaj po raz pierszy!" << endl;
         time_t lastVisit = time(NULL);
         session->setAttribute("lastVisit", lastVisit);
     }
     out << "</body></html>" << endl;
 }
开发者ID:rzymek,项目名称:cxxsp,代码行数:16,代码来源:simple.cpp

示例10: doPost

	// POST 方法
	virtual bool doPost(HttpServletRequest& req, HttpServletResponse& res)
	{
		first_ = false;

		logger("request one now");

		// 创建 HTTP 响应头
		res.addCookie("name1", "value1");
		res.addCookie("name2", "value2", ".test.com", "/", 3600 * 24);
		res.setChunkedTransferEncoding(true);
		res.setKeepAlive(true);
		//		res.setStatus(400);  // 可以设置返回的状态码

		// 两种方式都可以设置字符集
		if (0)
			res.setContentType("text/xml; charset=gb2312");
		else
		{
			res.setContentType("text/xml");
			res.setCharacterEncoding("gb2312");
		}

		// 获得 HTTP 请求的数据类型,正常的参数类型,即 name&value 方式
		// 还是 MIME 数据类型,还是数据流类型
		http_request_t request_type = req.getRequestType();
		if (request_type == HTTP_REQUEST_NORMAL)
			return doParams(req, res);
		else if (request_type == HTTP_REQUEST_MULTIPART_FORM)
			return doUpload(req, res);
		assert(request_type == HTTP_REQUEST_OCTET_STREAM);
		return doOctetStream(req, res);
	}
开发者ID:10jschen,项目名称:acl,代码行数:33,代码来源:ssl_server.cpp

示例11: doPost

	virtual bool doPost(HttpServletRequest& req, HttpServletResponse& res)
	{
		const char* sid = req.getSession().getAttribute("sid");
		if (*sid == 0)
			req.getSession().setAttribute("sid", "xxxxxx");
		sid = req.getSession().getAttribute("sid");

		const char* cookie1 = req.getCookieValue("name1");
		const char* cookie2 = req.getCookieValue("name2");

		// 创建 HTTP 响应头
                res.addCookie("name1", "value1");
		res.addCookie("name2", "value2", ".test.com", "/", 3600 * 24);
//		res.setStatus(400);  // 可以设置返回的状态码

		// 两种方式都可以设置字符集
		if (0)
			res.setContentType("text/xml; charset=gb2312");
		else
		{
			res.setContentType("text/xml");
			res.setCharacterEncoding("gb2312");
		}

		const char* param1 = req.getParameter("name1");
		const char* param2 = req.getParameter("name2");

		// 创建 xml 格式的数据体
		xml body;
		body.get_root().add_child("root", true)
			.add_child("sessions", true)
				.add_child("session", true)
					.add_attr("sid", sid ? sid : "null")
					.get_parent()
				.get_parent()
			.add_child("cookies", true)
				.add_child("cookie", true)
					.add_attr("name1", cookie1 ? cookie1 : "null")
					.get_parent()
				.add_child("cookie", true)
					.add_attr("name2", cookie2 ? cookie2 : "null")
					.get_parent()
				.get_parent()
			.add_child("params", true)
				.add_child("param", true)
					.add_attr("name1", param1 ? param1 : "null")
					.get_parent()
				.add_child("param", true)
					.add_attr("name2", param2 ? param2 : "null");
		string buf;
		body.build_xml(buf);

		// 发送 http 响应头
		if (res.sendHeader() == false)
			return false;
		// 发送 http 响应体
		if (res.getOutputStream().write(buf) == -1)
			return false;
		return true;
	}
开发者ID:nitsel88,项目名称:acl,代码行数:60,代码来源:http_servlet.cpp

示例12: DoTrace

void HttpServlet::DoTrace(HttpServletRequest& request, HttpServletResponse& response)
{
  std::string CRLF = "\r\n";
  std::string responseString = "TRACE " + request.GetRequestUri() +
                               " " + request.GetProtocol();

  std::vector<std::string> reqHeaders = request.GetHeaderNames();

  for (std::size_t i = 0; i < reqHeaders.size(); ++i)
  {
    responseString += CRLF + reqHeaders[i] + ": " +
                      request.GetHeader(reqHeaders[i]);
  }

  responseString += CRLF;

  response.SetContentType("message/http");
  response.SetContentLength(responseString.size());
  response.GetOutputStream() << responseString << std::flush;
  return;
}
开发者ID:CppMicroServices,项目名称:CppMicroServices,代码行数:21,代码来源:HttpServlet.cpp

示例13: doGet

    void doGet(const HttpServletRequest& request, HttpServletResponse &response) {
        //dbg_stop();

        response.setContentType("text/html");
        ostream& out = response.getOutputStream();
        out << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""
            "\"http://www.w3.org/TR/html4/loose.dtd\">" << endl;
        out << "<html><head><title>test</title></head><body>" << endl;

        out << "<table border>" << endl;
        dbi_result result = dbi_conn_query(conn, "SELECT * FROM store_products");
        while(dbi_result_next_row(result)) {
            out << "<tr>" << endl;

            long product_id = dbi_result_get_long(result, "product_id");
            long category_id = dbi_result_get_long(result, "category_id");
            string name = dbi_result_get_string(result, "product_name");
            float price = dbi_result_get_float(result, "price");
            string img = dbi_result_get_string(result, "image_url");
            string desc = dbi_result_get_string(result, "description");
            bool recomended = dbi_result_get_long(result, "is_recommended")==1;

            out << "<td>" << product_id << "</td>" <<endl;
            out << "<td>" << category_id << "</td>" <<endl;
            out << "<td>" << name << "</td>" <<endl;
            out << "<td>" << price << "</td>" <<endl;
            out << "<td>" << img << "</td>" <<endl;
            out << "<td>" << desc << "</td>" <<endl;
            out << "<td>" << recomended << "</td>" <<endl;
            out << "</tr>" << endl;
        }
        out << "</table>" << endl;
        out << "</body></html>" << endl;

        dbi_result_free(result);
    }
开发者ID:rzymek,项目名称:cxxsp,代码行数:36,代码来源:test2.cpp

示例14: add_to_cart

void ProductDetails::add_to_cart(HttpServletRequest& request, HttpServletResponse &response) {
    HttpSession* session = request.getSession(false);
    if(!session) throw runtime_error("no session");
    typedef vector<cart_item> shopping_cart;
    shopping_cart cart = session->getAttribute<shopping_cart>("cart");
    cart_item item;
    item.quantity = boost::lexical_cast<int>(request.getParameter("quantity"));
    item.product = fetch(request.getParameter("product_id"));
    if(item.quantity <= 0)
        throw runtime_error("Quantity is invalid. It must be a positive number");
    cart.push_back(item);

    session->setAttribute("cart",cart);
    response.sendRedirect("ShoppingCart.sxx");
}
开发者ID:rzymek,项目名称:cxxsp,代码行数:15,代码来源:ProductDetails.cpp

示例15: upgradeWebsocket

static bool upgradeWebsocket(HttpServletRequest& req, HttpServletResponse& res)
{
	const char* ptr = req.getHeader("Connection");
	if (ptr == NULL)
		return false;
	if (acl_strcasestr(ptr, "Upgrade") == NULL)
		return false;
	ptr = req.getHeader("Upgrade");
	if (ptr == NULL)
		return false;
	if (strcasecmp(ptr, "websocket") != 0)
		return false;
	const char* key = req.getHeader("Sec-WebSocket-Key");
	if (key == NULL || *key == 0)
	{
		logger_warn("no Sec-WebSocket-Key");
		return false;
	}

	http_header& header = res.getHttpHeader();
	header.set_upgrade("websocket");
	header.set_ws_accept(key);
	return true;
}
开发者ID:LazyPlanet,项目名称:acl,代码行数:24,代码来源:HttpServlet.cpp


注:本文中的HttpServletResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。