重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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;
}
}
package web;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import bean.Stock;
import net.sf.json.JSONArray;
public class ActionServlet extends HttpServlet{
public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
System.out.println("service()");
//获得请求路径
String uri=request.getRequestURI();
System.out.println(uri);
//分析请求路径
String action=uri.substring(uri.lastIndexOf("/"),uri.lastIndexOf("."));
System.out.println(action);
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
if("/quoto".equals(action)){
//模拟生成几支股票信息
List stocks=new ArrayList();
Random r=new Random();
for(int i=0;i<8;i++){
Stock s=new Stock();
s.setCode("600877"+r.nextInt(10));
s.setName("中国嘉陵"+r.nextInt(100));
s.setPrice(10+r.nextInt(1000));
stocks.add(s);
}
//fromObject方法的参数可以是属猪或者结合
JSONArray jsonArr=JSONArray.fromObject(stocks);
String jsonStr=jsonArr.toString();
System.out.println(jsonStr);
out.println(jsonStr);
}
}
}
ajax-day02
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
action
web.ActionServlet
action
*.do
4.0.0
cn.qiuuuu
ajax-day02
0.0.1-SNAPSHOT
war
net.sf.json-lib
json-lib
2.4
jdk15
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
Insert title here
股票行情
代码
名称
价格
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。