我一直试图通过dynatree中的ajax调用来调用java servlet。问题是如何在URL的末尾添加锚点?
http://.../TreeBuilder?caller=Applications
我的jquery代码看起来像这样
onLazyRead: function(node){
node.appendAjax({
url: "/TreeBuilder",
data: {"key": node.data.key,
"mode": "all"
},
success: function(node) {
我的servlet doGet方法看起来像这样
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();
}
}
答案 0 :(得分:0)
解决了!
函数appendAjax中数据对象中的键值对实际上会像这样附加到url的末尾
http://.../TreeBuilder?key=value
然后我们可以继续在servlet的doGet函数中获取参数。