//jsp中ajax请求
$.ajax({
type: "POST",//请求方式
url: "../display",//地址,就是action请求路径
data: "method=getNum1",//数据类型text xml json script jsonp
dataType:"json",//指定返回值的类型
success: function(msg){//返回的参数就是 action里面所有的有get和set方法的参数
}
},error:function(msg)
{
console.info("error!!!");
console.info(msg);
}
});
//servlet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Content-Type", "text/html; charset=UTF-8");
String method=request.getParameter("method");
if(method.equals("getNum1"))
{
getNum1(response);
}
}
public void getNum1()
{
...
}