I have been trying to call java servlet through ajax calls in dynatree. The problem is how do I add an anchor at the end of the url like this?
http://.../TreeBuilder?caller=Applications
My jquery code looks like this
onLazyRead: function(node){
node.appendAjax({
url: "/TreeBuilder",
data: {"key": node.data.key,
"mode": "all"
},
success: function(node) {
My servlet doGet method looks like this
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException {
String caller = request.getParameter("caller");
OrganisationService oService = new OrganisationService();
try {
// Object obj = parser.parse(new FileReader("d:\\test.json"));
// loop array
JSONArray children = null;
try {
children = oService.getChildren(caller);
} catch (SQLException e) {
e.printStackTrace();
}
logger.info("The children passed are" + children.toJSONString());
response.setContentType("application/json");
response.getWriter().write(children.toJSONString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Solved it!
The key-value pairs in data object within the function appendAjax actually gets appended at the end of url like this
http://.../TreeBuilder?key=value
then we can go ahead and get the parameters in the doGet function of the servlet.