What is a good path for a Servlet?
Hi here,
So my servlet got a path "/bin/...." copying a post from Adobe help.
But inside Dispatcher
bin is not allowed, of course I can allow it. But ....
what path would be OK for a servlet?
Hi here,
So my servlet got a path "/bin/...." copying a post from Adobe help.
But inside Dispatcher
bin is not allowed, of course I can allow it. But ....
what path would be OK for a servlet?
WHen using paths - (which is a valid SLing way- https://sling.apache.org/documentation/the-sling-engine/servlets.html) - you can invoke the Servlet without accessing a JCR node.
That is - you can use an AJAX request or write HTTP GET/POSTs. All of these are accomplished without accesing a JCR node. So when you want to invoke a servlet from outside of AEM (a web client or desktop app that does not access a JCR node or using an AJAX request) - binding by path is the way to do it.
Here is an example of a path - under bin - and an AJAX call invoking the servlet:
$('#submit').click(function() {
var failure = function(err) {
alert("Unable to retrive data "+err);
};
//Get the user-defined values that represent claim data to persist in the Adobe CQ JCR
var myFirst= $('#FirstName').val() ;
var myLast= $('#LastName').val() ;
var date= $('#DateId').val() ;
var cat= $('#Cat_Id').val() ;
var state= $('#State_Id').val() ;
var details= $('#Explain').val() ;
var city= $('#City').val() ;
var address= $('#Address').val() ;
var claimId = createUUID();
//Use JQuery AJAX request to post data to a Sling Servlet
$.ajax({
type: 'POST',
url:'/bin/mySearchServlet',
data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,
success: function(msg){
var json = jQuery.parseJSON(msg);
var msgId= json.id;
var lastName = json.lastname;
var firstName = json.firstname;
$('#ClaimNum').val(msgId);
$('#json').val("Filed by " + firstName + " " + lastName);
}
});
});
In Dispatcher - you can allow access to this path. See:
https://docs.adobe.com/docs/en/cq/5-6-1/deploying/security_checklist.html
That way - AJAX requests will work
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.