How do I run POCO C++ server pages?
I'm a beginner in C++ server pages. I have tried C++ Server Pages by micronovae, but couldnt connect ODBC it used to give link error "undefined reference to SQLAllocHandle@12
", I could not resolve it. Similar to micronovae,POCO also provides C++ Server Pages. so thought of try it. I tried one sample from http://pocoproject.org/docs/PageCompilerUserGuide.html#0 .
What I did is, firstly created a file called TimeHandler.html along with following contents inside it:
<%@ page class="TimeHandler" %>
<%!
#include "Poco/DateTime.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeFormat.h"
using Poco::DateTime;
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
%>
<%
DateTime now;
std::string dt(DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT));
%>
<html>
<head>
<title>Time Sample</title>
</head>
<body>
<h1>Time Sample</h1>
<p><%= dt %></p>
</body>
</html>
Then, I used the commandline Pagecompiler tool, i.e., CPSPCD from command prompt, and it generated following two files,..
1) TimeHandler.cpp
#include "TimeHandler.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTMLForm.h"
#line 2 "C:\\Users\\Admin\\Desktop\\data structures\\vinz\\TimeHandler.html"
#include "Poco/DateTime.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeFormat.h"
using Poco::DateTime;
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
void TimeHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
Poco::Net::HTMLForm form(request, request.stream());
std::ostream& responseStream = response.send();
responseStream << "";
responseStream << "\n";
responseStream << "";
responseStream << "\n";
responseStream << "\n";
responseStream << "";
#line 13 "C:\\Users\\Admin\\Desktop\\data structures\\vinz\\TimeHandler.html"
DateTime now;
std::string dt(DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT));
responseStream << "\n";
responseStream << "<html>\n";
responseStream << "<head>\n";
responseStream << "<title>Time Sample</title>\n";
responseStream << "</head>\n";
responseStream << "<body>\n";
responseStream << "<h1>Time Sample</开发者_JS百科h1>\n";
responseStream << "<p>";
#line 23 "C:\\Users\\Admin\\Desktop\\data structures\\vinz\\TimeHandler.html"
responseStream << ( dt );
responseStream << "</p>\n";
responseStream << "</body>\n";
responseStream << "</html>";
}
2) TimeHandler.h
#ifndef TimeHandler_INCLUDED
#define TimeHandler_INCLUDED
#include "Poco/Net/HTTPRequestHandler.h"
class TimeHandler: public Poco::Net::HTTPRequestHandler
{
public:
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
};
#endif // TimeHandler_INCLUDED
And then I created new project in VS 2010 and added these two files and compiled. There were few issues, but later I updated environment variables and it went on fine. But there is one last error, "....Unresolved symbol _main....".
There was no main inside it.. so how do I run this program?? if not this program, atleast would someone give an overview as to how to embed C++ code inside html, compile and run it..!
The samples you show only create the individual page (handler) implementation.
You need to add an actual HTTPServer to serve that page.
See: http://pocoproject.org/docs/Poco.Net.HTTPServer.html
There is a sample in the sources download under
poco-1.4.2p1.zip\poco-1.4.2p1\Net\samples\HTTPTimeServer
You should be able to get something working from there
精彩评论