0

I don't know if it's possibile . When I create a webapi I must declare in web.xml the related class/url

  <servlet-mapping>
        <servlet-name>myServlet</servlet-name>
        <url-pattern>/myServlet.htm</url-pattern>
        <!-- WebApi -->
        <url-pattern>/Timbrature2/*</url-pattern>
        <url-pattern>/Timbrature2.json/*</url-pattern>
        <url-pattern>/Timbrature2.xml/*</url-pattern>
        <url-pattern>/Timbrature/*</url-pattern>
        <url-pattern>/Timbrature.json/*</url-pattern>
        <url-pattern>/Timbrature.xml/*</url-pattern>
        <url-pattern>/TimbratureMobile/*</url-pattern>
        <url-pattern>/TimbratureMobile.json/*</url-pattern>
        <url-pattern>/TimbratureMobile.xml/*</url-pattern>
        <url-pattern>/$metadata</url-pattern>
    </servlet-mapping>

but if my webapp load from jars dynamic code can I add a "new" class to be used as a REST endpoint?

Read Apache documentation, tryied various configurations but nothing

  • It's not entirely clear what you are trying to do. Are you asking if it's possible to add another API call (e.g. with a different URL pattern) without modifying `web,.xml`? – Christopher Schultz Mar 30 '23 at 17:27
  • Yes exactly... i've understood that a webapi url pattern must be registered in web.xml.. can i add another url at rendimento? – Denis De Pauli Mar 31 '23 at 18:09

1 Answers1

0

If you want one servlet to handle everything, you can register it to broad URL patterns like

<url-pattern>/api/*</url-pattern>

It's worth reading the Servlet Specification and specifically section 12.2 (in the 4.0 release of the spec) which covers "Specification of Mappings". This describes the kinds of url-mappings which are possible.

Another option is to use @WebServlet annotations in your code (covered in section 8.1.1 of the above document) to establish a mapping from within your code. I have a preference for the declarative mapping found in web.xml because all mappings are co-located rather than spread out across arbitrary source files whose source may not always be available.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77