Jetty Difference between ServletContextHandler and WebAppContext and its usage

久未见 提交于 2019-12-23 03:47:27

问题


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 ?

回答1:


  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.



来源:https://stackoverflow.com/questions/36964336/jetty-difference-between-servletcontexthandler-and-webappcontext-and-its-usage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!