Servlet 接口ITeye - 凯发娱乐

Servlet 接口ITeye

2019年03月04日15时47分07秒 | 作者: 飞荷 | 标签: 用户名,暗码 | 浏览: 1775

public void doGet(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{

String username = req.getParameter("username");//用户名

String password = req.getParameter("password");//暗码

if(username.equals("111") password.equals("111")){

JSONObject datas = new JSONObject();

JSONArray rs = new JSONArray();

JSONObject obj = new JSONObject();

obj.put("uid", "34860");

obj.put("uname", "411");

obj.put("utype", "5");

obj.put("nickname", "abcdef");

obj.put("myphoto", "11111111111111111111111");

rs.add(obj);

datas.put("result", "1");

datas.put("userinfo",rs);

String info = datas.toString();

System.out.println(info);

req.setAttribute("info", info);

req.getRequestDispatcher("text.jsp").forward(req,resp);

}else{

 

}

 

}

 

//-

String httpStr = "https://api.douban.com/v2/book/1220562";

String theWord = null;

URL url = new URL(httpStr);

InputStream ins = url.openConnection().getInputStream();

BufferedReader br = new BufferedReader(new InputStreamReader(ins,"utf-8"),2048);

theWord = br.readLine();

System.out.println(theWord);

JSONObject jsonArray = JSONObject.fromObject(theWord);

List list = new ArrayList();

String name = jsonArray.getString("rating"); 

System.out.println(name);

String publisher = jsonArray.getString("publisher"); 

System.out.println(publisher);

 

String author = jsonArray.getString("author");

System.out.println(author);

String pubdate = jsonArray.getString("pubdate");

System.out.println(pubdate);

String price = jsonArray.getString("price");

System.out.println(price);

 

for (int i = 0; i jsonArray.size(); i++) {

  Object o = jsonArray.get(i);

  JSONObject jsonObject = JSONObject.fromObject(o);

  Shop Person = (Shop) JSONObject.toBean(jsonObject, Shop.class);

  list.add(Person);

 // list.add(Person);

}

 

 

//

List list = new ArrayList();

 

JSONArray arr = jsonArray.getJSONArray("books");

    for(int i=0;i arr.size();i++){

    JSONObject jb = (JSONObject)arr.get(i);

    Shop person = new Shop();

    person.setAuthor(jb.get("author").toString());

    person.setImage(jb.get("image").toString());

    person.setTitle(jb.get("title").toString());

    list.add(person);

    }

   

    request.setAttribute("list", list);

    request.getRequestDispatcher("/book_list.jsp").forward(request, response);

 

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表凯发娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章