先来看一下最后的显示效果:
每隔5秒刷新一次表格
1.创建一个名为ajax2的web项目,具体步骤见:用Intellij idea新建一个java web+Servlet项目
2.创建如图所示文件:
3.写Stock这个Javabean对象,包括股票代码,名称,价格:
package bean;
public class Stock {
private String code;
private String name;
private int price;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
4.写后端代码,ActionServlet:
package web;
import bean.Stock;
import net.sf.json.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servle