use*_*917 11
Jetty can act as a http server and also a servlet container who deals with the lifecycle of servlets (init, service, destroy) etc. A servlet is a java class that extends HttpServlet class and can override init, service, destroy methods etc. Once jetty receives a request whose URL matches with that of a servlet, it loads the servlet in memory (if not already there), calls service method, and keeps it in memory until it destroys it.
Jersey library has provided a standard way of writing RESTful APIs where classes are annotated with tags like say GET/POST
etc and the URL. These classes are called resource classes. It has also provided a servlet whose name is ServletContainer
to hook up with Jetty's servlet container, that intercepts Jetty's request to process servlet (like for any servlet request to jetty
this is the one class, that receives the request first).
What this servlet does is it examines the request, matches with the resource classes URL that it is informed about, and then transfers
control to that method of that resource class (i think it uses reflection for this routing). Therefore, the resource
classes are not servlet itself, but the ServletContainer class of jersey is the only servlet active in the system.
The list of resource classes ServletContainer knows about is configured by this property called "com.sun.jersey.config.property.packages"
使用 Jersey 的好处是实现你的 REST API 是你使用标准的方式编写你的代码,如果将来需要,你可以部署到任何其他标准的 servlet 容器,比如 tomcat,...
| 归档时间: |
|
| 查看次数: |
3979 次 |
| 最近记录: |