« Download 0.0.4a C++ Web Framework / Server
« Benchmark & Code Revision
I am still a bit new to c++, and the make platform so hopefully this will go okay.
unzip webserver-0.0.4.zip
cd webserver
make
cd ../website
make
website demo requires sqlite3 devel libs
./dist/Debug/GNU-Linux-x86/website
Goto your browser http://localhost:8181/ and the demo should run!
#include "WebController.h"
#include "WebServer.h"
#include "ServerSocket.h"
#include "SocketException.h"
#include <string>
#include <iostream>
#include <map>
class HomeController : public WebController {
public:
void get() {
this->session->set("foo", "bar");
this->response->body.append("\
<html>\
<head>\
<title>Before</title>\
</head>\
<body>\
" + this->request->get("asdfasdf") + "\
<form action=\"\" method=\"post\">\
<input type=\"hidden\" name=\"asdfasdf\" value=\"dsfasdfasdf\" />\
<input type=\"submit\" name=\"submit\" value=\"Push\" />\
</form>\
<br /><a href=\"/after\">After</a>\
</body>\
</html>\
");
}
};
class AfterController : public WebController {
public:
void get() {
this->response->body.append("\
<html>\
<head>\
<title>After</title>\
</head>\
<body>\
" + this->session->get("foo") + "\
<br /><a href=\"/\">Before</a>\
</body>\
</html>\
");
}
};
int main(int argc, char* argv[]) {
WebServer* server = new WebServer();
server->port = 8181;
server->addController("/", new HomeController());
server->addController("/after", new AfterController());
server->run();
delete server;
return 0;
}
« Back to my notebook