예제 #1
0
void FormTestServlet::doGet(HttpServletRequest& req, HttpServletResponse& resp)
{
	ServletOutputStream& ostr = resp.getOutputStream();

	ostr <<
		"<html>\n"
		"<head>\n"
		"<title>POCO Form Server Sample</title>\n"
		"</head>\n"
		"<body>\n"
		"<h1>POCO Form Server Sample</h1>\n"
		"<h2>GET Form</h2>\n"
		"<form method=\"GET\" action=\"/ServletTest/FormTestServlet\">\n"
		"<input type=\"text\" name=\"text\" size=\"31\">\n"
		"<input type=\"submit\" value=\"GET\">\n"
		"</form>\n"
		"<h2>POST Form</h2>\n"
		"<form method=\"POST\" action=\"/ServletTest/FormTestServlet\">\n"
		"<input type=\"text\" name=\"text\" size=\"31\">\n"
		"<input type=\"submit\" value=\"POST\">\n"
		"</form>\n";
		
	ostr << "<h2>Request</h2><p>\n";
	ostr << "Method: " << req.getMethod() << "<br>\n";
	ostr << "URI: " << req.getRequestURI() << "<br>\n";
	
	std::vector<std::string> names = req.getParameterNames();
	std::vector<std::string>::iterator it = names.begin();
	for(; it != names.end(); ++it)
		ostr << *it << ":" << req.getParameter(*it);

	ostr << "</p>";

	ostr << "</body>\n";
}
예제 #2
0
void TestServlet::doGet(HttpServletRequest& req, HttpServletResponse& resp)
{ 
	std::ostringstream ss("");
	ss << ++_counter << ") TestServlet:" << std::endl;

	std::cout << ss.str() << std::endl;

	log(ss.str());

	log("TestServlet: This is a hello from TestServlet\n");

	ServletOutputStream& out = resp.getOutputStream();

	ss.str("");
	ss << "<html><body>Servlet access count: " << _counter;
	out.println(ss.str());

	if("" == _sessionId)
	{
		const HttpSession* pSession = req.getSession();
		
		if(pSession) _sessionId = pSession->getId();
	}

	out.println("<br> Servlet Name:" + getServletName());
	out.println("<br> Session Id:" + _sessionId);
	out.println("<hr>");

	std::vector<std::string> names = getInitParameterNames();
	std::vector<std::string>::iterator it = names.begin();
	out.println("<ul><b>Servlet Init Parameters:</b><br>");
	for(; it != names.end(); ++it)
	{
		ss.str("");
		ss << "<li><b>" << *it << "</b>: " << getInitParameter(*it) << "<br>";
		out.println(ss.str());
	}
	out.println("</ul>");

	names = req.getParameterNames();
	out.println("<ul><b>Request Parameters:</b><br>");
	it = names.begin();
	for(; it != names.end(); ++it)
	{
		ss.str("");
		ss << "<li><b>" << *it << "</b>:" << req.getParameter(*it) << "<br>";
		out.println(ss.str());
	}
	out.println("</ul>");

  out.println("</body></html>");
}
예제 #3
0
파일: Products.cpp 프로젝트: rzymek/cxxsp
string Products::make_naviLink(HttpServletRequest& request) {
    auto_ptr< vector<string> > names_ptr = request.getParameterNames();
    vector<string>& names = *names_ptr;
    string link;
    for(unsigned i=0;i<names.size(); ++i) {
        if(names[i] == "productsPage")
            continue;
        link += link.empty()?'?':'&';
        link += names[i] + "=" + request.getParameter(names[i]);
    }
    link += (link.empty()?'?':'&') + string("productsPage=");
    return ("Products.sxx"+link);

}
예제 #4
0
void DefaultTestServlet::doGet(HttpServletRequest& req, HttpServletResponse& resp)
{
	std::ostringstream ss("");
	ss << ++_counter << ") TestServlet:" << std::endl;

	log(ss.str());

	log("TestServlet: This is a log entry from DefaultTestServlet\n");

	ServletOutputStream& out = resp.getOutputStream();

	ss.str("");
	std::string sessionId = req.getSession()->getId();

	ss << "<html><body>Hello world #" << _counter
		 << "<br>from servlet [" << this->getServletName() 
		 << "]<br>Session ID: [" << sessionId << ']';
	out.println(ss.str());

	std::vector<std::string> names = getInitParameterNames();
	std::vector<std::string>::iterator it = names.begin();
	out.println("<ul><b>Servlet Init Parameters:</b><br>");
	for(; it != names.end(); ++it)
	{
		ss.str("");
		ss << "<li><b>" << *it << "</b>: " << getInitParameter(*it) << "<br>";
		out.println(ss.str());
	}
	out.println("</ul>");

	names = req.getParameterNames();
	out.println("<ul><b>Request Parameters:</b><br>");
	it = names.begin();
	for(; it != names.end(); ++it)
	{
		ss.str("");
		ss << "<li><b>" << *it << "</b>:" << req.getParameter(*it) << "<br>";
		out.println(ss.str());
	}
	out.println("</ul>");

  out.println("</body></html>");
}
예제 #5
0
파일: test.cpp 프로젝트: rzymek/cxxsp
    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;
    }