I'm trying to write a REST servlet that returns a list at '/connections' and an item at '/connections/{id}', but GET requests only ever go to the first doGet() function. I can't figure out how to write the web.xml to handle the id field.
What is it that I'm doing wrong in this code?
@Path("connections")
public class Connections extends HttpServlet {
public Connections() {
super();
}
@GET
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//return list
}
@GET
@Path("{id}")
protected void doGet(HttpServletRequest request, HttpServletResponse response, @PathParam("id") String id)
throws ServletException, IOException {
//return item from list
}
}
and the web.xml
<web-app>
<display-name>test</display-name>
<servlet>
<servlet-name>connections</servlet-name>
<servlet-class>com.apiEndpoints.Connections</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>connections</servlet-name>
<url-pattern>/connections</url-pattern>
<url-pattern>/connections/*</url-pattern>
</servlet-mapping>
</web-app>