Project

General

Profile

Actions

Support #5997

closed

How to generate a fully custom page

Added by Julien Ladge about 7 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
10/13/2017
Due date:
% Done:

0%

Estimated time:

Description

Hi

I would like to know how I can generate my own stuff.

For example, if I request in a browser www.mysite.com?key=toto, I would like it gives me blank page with only toto (By blank, I mean without Wt stuff like html tags).

I know how to get parameters. But I don't know how to print a raw text.

view-source:http://www.mysite.com:8080/?key=toto

have to return only:

toto

Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
    const std::string * apikey = env.getParameter("key");
    if( apikey != NULL && *apikey!="")
    {
        return printKey(apikey); //??
    }else
         return new Wt::WApplication(env);
}


int main(int argc, char **argv)
{
        QCoreApplication app(argc, argv);        
        return Wt::WRun(argc, argv, &createApplication);
}
Actions #1

Updated by Julien Ladge about 7 years ago

Thanks to stackoverflow

Resolved by:

Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
    return new Website(env);// custom website
}

class MyResource : public Wt::WResource
{
public:
    MyResource(){}
    virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response)
    {
        const std::string * key = request.getParameter("key");
        if( key != NULL && *key != "")
        {
            response.out() << *key;
        }
    }
};

int main(int argc, char **argv)
{

        Wt::WServer server(argv[0]);
        server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
        server.addResource(new MyResource, "/api");
        server.addEntryPoint(Wt::Application, createApplication);
        if (server.start())
                {
                    Wt::WServer::waitForShutdown();
                    server.stop();
        }
        return 0;
    }
}
Actions #2

Updated by Roel Standaert about 7 years ago

  • Status changed from New to Closed

I'm happy to see you figured it out. Note, though, that addResource does not transfer ownership, so if you don't want tools like valgrind to complain, you'll have to for example create the resource on the stack before starting the server. See the example in examples/te-benchmark.

Actions

Also available in: Atom PDF