2

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 ?
Débora
  • 5,816
  • 28
  • 99
  • 171

1 Answers1

4
  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.

jesse mcconnell
  • 7,102
  • 1
  • 22
  • 33
  • 1
    Thanks jesse for the answer. I tried to use only the ServletContextHandler to handle JSP and other viewables (js,css etc). But none of attempts were successful. Most of samples in the Internet is about JSP with WebAppContext configuration. Some documents and samples of ServletContextHandler for JSP did not worked and other people have also faced the same. If there is a working hosted project (for instance: github) for JSP implemented though ServletContextHandler, please let me have. – Débora May 02 '16 at 14:32