Source code sample

The necessary sourcecode for the Hello World servlet.
#include <cppuhelper/weak.hxx>
#include <htmlhelper/basehttpservlet.hxx>
#include <htmlhelper/writer.hxx>
#include <htmlhelper/macros.hxx>

// use some of the stand
using namespace com::sun::star::lang;
using namespace com::sun::star::uno;
using namespace com::sun::star::io;
using namespace net::sourceforge::unoservlet::http;
using namespace net::sourceforge::unoservlet;
using namespace rtl;
using namespace cppu;
using namespace htmlhelper;

// Choose your own namespace here to avoid unix symbol
// name clashes at runtime.
namespace uno_servlet_samples
{

/* This is your servlet class declaration.
   In general, there will only be one instance per process */
class HelloWorld : public BaseHttpServlet
{
public:
	HelloWorld( const Reference< XComponentContext > &r,
                const OUString &sImplementationName,
                const Sequence< OUString > &seqServices)
		: BaseHttpServlet( r , sImplementationName, seqServices )
		{}
public:
	virtual void SAL_CALL doGet( const Reference< XHttpServletRequest >& aRequest,
								 const Reference< XHttpServletResponse >& aResponse )
		throw(ServletException, IOException, RuntimeException);
};


/* This method is called for every http request for
   net.sourceforge.HelloWorld !
 */  
void  HelloWorld::doGet( const Reference< XHttpServletRequest >& aRequest,
						 const Reference< XHttpServletResponse >& aResponse )
	throw(ServletException, IOException, RuntimeException)
{
    // A buffered writer stores all appended strings within a buffer,
    // the destructor (or the method flush()) writes it through to the
    // webserver. This is done for efficiency reasons, when the webserver
    // runs in a different process.
    // Additionally it converts all strings from unicode into the desired
    // encoding.
	BufferedWriter writer(
        aResponse->getOutputStream(),
        RTL_TEXTENCODING_ISO_8859_1 );

    // write the famous hello world
	writer.append( "<html><body>Hello World !</body></html>" );
}

}

/* This is glue code, which instantiates your servlet.
   net.sourceforge.HelloWorld is the servlet name,
   which you need to type in the browsers URL.
*/
using namespace uno_servlet_samples;
HTMLHELPER_STDMETHODS_DECL( HelloWorld )
HTMLHELPER_STDMETHODS_IMPL( HelloWorld, "net.sourceforge.HelloWorld" , "net.sourceforge.comp.unoservlet.HelloWorld" )
static struct ImplementationEntry g_entries[] =
{
	HTMLHELPER_STDMETHODS_ENTRY( HelloWorld ),
	{0,0,0,0,0,0}
};
HTMLHELPER_COMPONENT_EXPORTS( g_entries );