Home - novalexei/mod_servlet GitHub Wiki

C++ Servlet API and container

This is where simplicity of Servlet API, power of C++ language and performance of Apache2 httpd server meet!

This is my attempt to implement C++ API for server side web development. The API is based on Java Servlet API. The container is implemented as an Apache2 module.

What is a servlet anyways? A servlet is a server-resident program that typically runs automatically in response to user request. It can process user input and/or generate the output dynamically.

The features of mod_servlet API:

  • Servlets;
  • Filters;
  • Sessions;
  • Cookies;
  • Redirects
  • Server side forwards and includes;
  • SSL related information;
  • Request streams, including multipart uploads;
  • Serving static content from web application;
  • and probably a lot of other stuff I cannot remember now.

How a simple HTML generating servlet looks like? This is how:

#include <iostream>
#include <servlet/servlet.h>

struct hello_servlet : public servlet::http_servlet
{
    void do_get(http_request& req, http_response& resp) override
    {
        resp.set_content_type("text/html");
        resp.get_output_stream() << "<h1>Hello, mod_servlet!</h1>";
    }
};

SERVLET_EXPORT(helloServlet, hello_servlet)

Full example with build instructions is here. You also get with it exceptional performance. Interested?

You'll need to build and install it first. Then configure it with Apache2. And you are ready to start development of your own web applications. Extensive API reference is also available.

Documentation pages:

⚠️ **GitHub.com Fallback** ⚠️