1b91fd75d816169af801a01052548739917bb5ad.svn-base 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. <%@ page language="java" pageEncoding="utf-8"%>
  2. <%@ page import="java.io.BufferedReader"%>
  3. <%@ page import="java.io.IOException"%>
  4. <%@ page import="java.io.InputStream"%>
  5. <%@ page import="java.io.InputStreamReader"%>
  6. <%@ page import="java.net.MalformedURLException"%>
  7. <%@ page import="java.net.URL"%>
  8. <%@ page import="java.net.URLEncoder"%>
  9. <%@ page import="java.net.URLConnection"%>
  10. <%
  11. request.setCharacterEncoding("utf-8");
  12. response.setCharacterEncoding("utf-8");
  13. StringBuffer readOneLineBuff = new StringBuffer();
  14. String content ="";
  15. String searchkey = request.getParameter("searchKey");
  16. String videotype = request.getParameter("videoType");
  17. try {
  18. searchkey = URLEncoder.encode(searchkey,"utf-8");
  19. URL url = new URL("http://api.tudou.com/v3/gw?method=item.search&appKey=myKey&format=json&kw="+ searchkey+"&pageNo=1&pageSize=20&channelId="+videotype+"&inDays=7&media=v&sort=s");
  20. URLConnection conn = url.openConnection();
  21. BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));
  22. String line = "";
  23. while ((line = reader.readLine()) != null) {
  24. readOneLineBuff.append(line);
  25. }
  26. content = readOneLineBuff.toString();
  27. reader.close();
  28. } catch (MalformedURLException e) {
  29. e.printStackTrace();
  30. } catch (IOException e2) {
  31. e2.printStackTrace();
  32. }
  33. response.getWriter().print(content);
  34. %>