jQuery Ajax url使用方式

jQuery Ajax的使用场景:
页面需要通过后台逻辑,但只需要局部刷新以显示新的内容。

jQuery Ajax url使用方式
1.servlet方式:
需要在struts.xml中写一个action,跳转地址写servlet;
需要重写init方法(为了使用spring注入的bean);
设置响应编码response.setContentType("text/html; charset=UTF-8");
使用request.getParameter()接收参数;
使用response.getWriter().print()传递页面内容;

2.action方式:
(1)json输出数据
需要struts2-json-plugin.jar;
需要在struts.xml中package extends="json-default";result type="json";
需要声明接收到的页面参数,并get,set;
需要声明要传到页面的值,生成get;
(2)在action中使用 ServletActionContext.getResponse()获取response后使用response.getWriter().print()来传递页面内容。
需要声明接收到的页面参数,并get,set;

原文地址:https://www.cnblogs.com/ggqzz/p/8421726.html