Support #1992

Add static resource to main application path

Added by Vitaly Volochay about 9 years ago. Updated almost 9 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


Hello! I wan't to know is it possible (and is it make sense) to add static resource with WServer::addResource to main application path.

I tried server->addResource(new MyResource, "/") but virtual method handleRequest is not calling when i send http requests to: localhost:port or ocalhost:port/

I think that this path is allready used by application so I can't add to it my resource. Is it true?


Updated by Vitaly Volochay about 9 years ago

And the other question is: what is a best way to pass data from static resource to WApplication.

I thought about 2 ways:

1) Emit signal from WResource::handleRequest() and somehow connect it with WApplication;

2) Use WServer::post from WResource::handleRequest() for post data to same session.


Updated by Koen Deforche about 9 years ago

  • Status changed from New to Feedback
  • Assignee set to Koen Deforche


By default, the application is deployed at '/' but you can change that using the ---deploy-path parameter, or by deploying the application on a different path using WServer API.

As to your second question, definitely the second method (2) is what you should do.




Updated by Vitaly Volochay almost 9 years ago

Trying to process http requests like this:

Wt::WServer server(argv[0]);
WebAppResource resource;
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
server.addEntryPoint(Wt::Application, createApplication);
server.addResource(&resource, "/service");


void WebAppResource::handleRequest(const Request& request, Response& response)


MyWebApplication* app = dynamic_cast<MyWebApplication*>(WApplication::instance());

WServer* server = WServer::instance();

if (app && server)


server~~post(app~~>sessionId(), boost::bind(&MyWebApplication::processHttp, app,




but when 'handleRequest' is called WApplication::instance() always returns null-pointer although it allready created, so I can't post event. What should i do?


Updated by Koen Deforche almost 9 years ago


a static resource is not linked to a WApplication, and thus WApplication::instance() is null by definition. Also, handleRequest() expects a response so you need to provide one by the time the function exits (or create a continuation otherwise).

What do you really want to do? Perhaps you want to set a cookie from the WApplication which you then check in the resource request which identifies the application context in which the request is to be handled?

What's the use-case? Why not use a normal dynamic WResource() within the application context?




Updated by Vitaly Volochay almost 9 years ago

Thanks for your answer I find another way to solve my problem.


Updated by Koen Deforche almost 9 years ago

  • Status changed from Feedback to Closed
  • Target version deleted (3.3.0)

Also available in: Atom PDF