November 22, 2014
Hot Topics:

Wt: C++ Web Toolkit Library Lets You Write Scripting-Independent Web Apps

  • June 6, 2008
  • By Victor Volkman
  • Send Email »
  • More Articles »

Wt (pronounced 'witty') is a C++ library and application server for developing and deploying web applications. Although Wt supplies a GUI, it is not your typical "framework", which locks you into someone's preconceived idea of how applications should be structured. Rather, Wt is widget-centric, and although inspired by existing C++ GUIs, it offers complete abstraction of any web-specific implementation details, all the way down to event handling and graphics support. It's probably not a coincidence that Wt is named similarly to the ever-popular Qt application development system!

In fact, none of today's so-called "page-based frameworks" (built on PHP or JSP/JSF derivatives) for developing web applications make abstraction of the peculiarities of the underlying implementation technologies. As a consequence, a developer must gain familiarity with a panoply of ever-changing technologies, including HTML/XHTML, JavaScript, CSS, AJAX, CGI, DHTML, SVG/VML/Canvas—just to name a few. Moreover, as soon as you drive a stick into the ground and choose a technology such as AJAX or JavaScript, you must take responsibility for graceful degradation when these pieces are missing in action due to or disabled for local security reasons. Little has changed in the structure of applications that follow the primarily page-centric paradigm of 1990s HTML. This means that you will need to design and maintain manually your client-server communication when using advanced AJAX techniques.

Generating HTML code or filling HTML templates is prone to security problems such as Cross-Site-Scripting (XSS), by unwillingly allowing JavaScript to be inserted in the page. Ironically, template frameworks cannot avoid this because as a developer you need to be able to insert self-written JavaScript to improve your web application.

In contrast, a web application developed with Wt is written in only one compiled language (C++), from which the library generates the necessary HTML/XHTML, JavaScript, CGI, or AJAX code. The responsibility of writing secure and browser-portable web applications is handled by Wt. For example, if available, Wt will maximally use JavaScript and AJAX, but applications developed using Wt will also function correctly when AJAX is not available, or when JavaScript is disabled, reverting to a plain HTML/CGI mechanism for communication between browser and server.

Typical use scenarios:

  • Web-based GUIs for embedded systems
  • Web-based GUIs that require integration with (existing) C++ libraries
  • Creating a port of existing C++ desktop applications to the web

Some benefits of using Wt:

  • Develop web applications like you develop C++ desktop applications.
  • Provides plain widgets, which work regardless of JavaScript availability.
  • Enables more polished or advanced functionality when JavaScript is available (without re-coding)
  • Built-in HTTPD and FastCGI for easy development and deployment.
  • A single specification for both client- and server-side validation and event handling (when using stateless slot implementations).
  • Generates standards compliant HTML or XHTML code.
  • Portable, anti-aliased graphics with VML, SVG, or HTML 5.
  • No exposure of business logic, which stays at the server.
  • Page load time is limited only by screen complexity, not application size.

Installation

Installing Wt for Windows is a bit harder than implementing it on a Linux host, primarily because there isn't anything as simple as Linux package management on Windows. So, it becomes a bit of a scavenger hunt, although there is a nice how-to document. Basically, you are responsible for locating the suggested versions of BoostPro Boost library (currently, 1.34.1). BoostPro requires asio, the asynchronous I/O model for C++. This is theoretically included in BoostPro 1.35 although I didn't test it out. These components in turn require cmake, a freeware "make" type utility.

Hello Wt!

You'll start off with a "hello world" type app that provides a simple CGI type form and see how this design can be realized by a C++ app. Unlike most apps that I write about, you can actually run it for yourself right now on the web! What you'll see first is a classic web form presentation shown in Figure 1. After you enter your name and click the Submit button ("Greet me."), it rewrites the page and more-or-less you are back to the initial state, as shown in Figue 2.

Figure 1: Hello world forms (entering text)

Figure 2: Hello world forms (after clicking Submit)





Page 1 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel