Question

I have the following Scala code to setup a Jetty server with Scalatra.

val server = new Server(8080)
val context = new WebAppContext()
context.setResourceBase("visualization")
context.addServlet(new ServletHolder(new CallTreeServlet(dataProvider)), "/*")
context.addServlet(new ServletHolder(new DataLoadingServlet(dataProvider)), "/*")
server.setHandler(context)

My problem is that it seems to work only if I register a single servlet.

If I register more than one, like I do in the code I posted, it loads only one of them.

Is it possible to load multiple servlets? I guess it is, but I can't figure out how.

If I try to load a page from the first servlet I got this error message that references only pages belonging to the second servlet:

Requesting "GET /callTrees" on servlet "" but only have:
GET /components
POST /load
POST /searchCallTrees
POST /selectPlugIn
Was it helpful?

Solution

To troubleshoot this, you should verify the servlet lifecycle. One convenient way to do this is to peruse the servlet container's logs to see what it reports while starting up the web application. It should tell you about each web app ( servlet context ) and each servlet . . .

However, I think I see what your problem is. Your servlet path mappings are kind of funky. It looks to me that you are mapping both servlets to receive ALL requests. This can't work, from a practical point of view, and might not work in terms of the servlet rules. From the servlet specification:

SRV.11.2
Specification of Mappings
In the Web application deployment descriptor, the following syntax is used to define
mappings:
• A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used
for path mapping.
• A string beginning with a ‘*.’ prefix is used as an extension mapping.
• A string containing only the ’/’ character indicates the "default" servlet of
the application. In this case the servlet path is the request URI minus the con-
text path and the path info is null.
• All other strings are used for exact matches only.

I suggest you make them both unique. As it looks now, you have them both at "/*" which is kind of like the "default servlet", but not . . .

Why not try "/first/" and "/second/" as a sanity check. Then move from there toward getting the configuration how you like.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top