Débora
Débora

Reputation: 5952

Jetty Difference between ServletContextHandler and WebAppContext and its usage

I have couple of questions.

  1. What is the main difference between WebAppContext and ServletContextHandler.
  2. My application has pages and restful service. Can ServletContextHandler be intended to use for Rest services than WebAppContext? (That means, is ServletContextHandler better to handler servlets to manage calls/requests to restful services?. But I have encountered running JSP s with ServletContextHandler) What are the advantages and disadvantages?
  3. Is there any drawbacks if I use two contexts: WebAppContext to load JSP and other static contents(like js, css) and ServletContextHandler to handle requests to restful requests ?

Upvotes: 2

Views: 1642

Answers (1)

jesse mcconnell
jesse mcconnell

Reputation: 7182

  1. WebAppContext represents a traditional webapp like a war file, the ServletContextHandler maps to a servlet
  2. If your rest services are backed by a servlet, then of course, a ServletContextHandler could be used to mound that rest service. JSP support is a servlet so you can just run it that way. The only real advantage or disadvantage is a WebappContext brings all the automatic deployment and wiring of things up with the web.xml...if you don't need that then don't use it and wire things up yourself.
  3. Not really, but if you are just using the WebappContext for jsp and static resources I would just use the JSPServlet and a DefaultServlet for the static content.

There are lots of different ways to do what you are looking to do. If you are comfortable dealing with servlet instances directly then just avoid the whole concept of the WebAppContext entirely. One other thing to be aware of, the WebappContext also provides classloader isolation for the deployed webapp, so that may or may not be a factor or something you are interested in.

Upvotes: 4

Related Questions