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


C++ HttpServletResponse::setContentType方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: doGet

    void doGet(HttpServletRequest& req, HttpServletResponse &res) {
        //dbg_stop();

        res.setContentType("text/html");
        ostream& out = res.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 << "PID: " << getpid() << "<hr>" << endl;

        auto_ptr< vector<string> > names = req.getHeaderNames();

        out << "<div style='border: solid black'>" << endl;
        out << "Headers:<ul>" << endl;
        for(unsigned i=0; i< names->size();++i) {
            out << "<li>" << (*names)[i] << "<ul>";
            auto_ptr< vector<string> > values = req.getHeaders((*names)[i]);
            for(unsigned j=0; j < values->size();++j) {
                out << "<li>" << (*values)[j] << "</li>";
            }
            out << "</ul>\n";
        }
        out << "</ul></div><br>\n";

        out << "<div style='border: solid black'>" << endl;
        out << "Cookies:<ul>" << endl;
        auto_ptr< vector<Cookie> > cookies = req.getCookies();
        for(unsigned i=0;i<cookies->size();++i)
            out << "<li><u>" <<  (*cookies)[i].getName() << "</u> "
                << (*cookies)[i].getValue() << "</li>\n" << endl;
        out << "</ul></div><br>\n";


        out << "<div style='border: solid black'>" << endl;
        out << "Parameters:<ul>" << endl;
        names = req.getParameterNames();
        for(unsigned i=0; i< names->size();++i) {
            out << "<li>" << (*names)[i] << "<ul>";
            auto_ptr< vector<string> > values = req.getParameterValues((*names)[i]);
            for(unsigned j=0; j < values->size();++j) {
                out << "<li>" << (*values)[j] << "</li>\n";
             //   Cookie c(names[i], req.getParameter(names[i]));
             //   res.addCookie(c);
            }
            out << "</ul>\n";
        }
        out << "</ul></div><br>";

        HttpSession* session = req.getSession();
        if(session){
            int cnt;
            if(session->isNew()){
                cnt = 1;
                session->setAttribute("cnt",cnt);
            }else{
                cnt = session->getAttribute<int>("cnt");
                cnt++;
                session->setAttribute("cnt",cnt);
            }
            out << "Your counter: " << cnt << endl;
            out << "<br>ID: " << session->getId() << endl;
        }else
            out << "<h4>No session</h4>";

        out << "</body></html>" << endl;
    }
开发者ID:rzymek,项目名称:cxxsp,代码行数:66,代码来源:test.cpp


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