ahaha0807_alg ahaha0807_alg - 11 months ago 109
Java Question

I want to using @WebServlet annotation and @Path annotation to same time in jetty

First, Please forgive me for my clumsy English.

[What I want to do]

I want to know

annotation by Servlet 3.0 and
annotation by Jersey 2.22.2, It is able to using same time?

[That I want is to help]

  • Can I use two annotations at the same time?

  • If I can use those annotations, is that way how to use?

Thank you.

Answer Source

@Path annotation defines a path to a RESTful Web service so when you have @Path("/SomeService") it will translate into www.yourapp.com/baseRestUrl/SomeService. You can also define it on the methods which provides REST services. Note that baseRestUrl is defined inside web.xml or in class which extends Application class.

On the other hand @WebServlet("/SomePath") states that Servlet will be listening for request on the www.yourapp.com/SomePath, it is basically replacement of servlet-mapping element in web.xml. You can still configure servlets like this, it's up to you whether you prefer XML or annotation configuration.