How is the call to servlet made? If there is an Ajax call via js, may be pass the resource path as a query param or form data making it a post call. That way we can do
String path = request.getParameter("resourcePath").
String path = request.getParameter("resourcePath");
Resource resource = request.getResourceResolver().resolve(path);
Other than may be we can try
String pagePath = request.getRequestURI();
Resource pageRes = request.getResourceResolver().resolve(pagePath);
//Once we get page resource find the desired resource node below that with resourcetype needed
For datasource there are examples of using Model classes too
In the datasource node we point the sling:resourceType property to a sighly html file that does a <sly data-sly-use.model="com.myproject.MyModel">
The MyModel class will contain the logic needed
I think I have seen similar implementation by @Arun_Patidar unable to find the example using Model class.
But this https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DatasourceJson.java seems to be using a servlet.