How to request and get a webpage using http request in jsp

前端 未结 2 2000
渐次进展
渐次进展 2021-01-23 13:49

How do I get an xml page (I mean an REST API from an web service), parse it and display it in my website, in jsp?

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 14:39

    I don't have the complete answer but here is how to get a web page at least. I'm trying to do something similar so will come back when I have more.

    <%@page import="java.net.*" %>
    <%@page import="java.io.*" %>
    
    <%
       URL dest = new URL("http://www.yahoo.com/");
       URLConnection yc = dest.openConnection();
       BufferedReader in = new BufferedReader(
                               new InputStreamReader(
                               yc.getInputStream()));
       String inputLine;
    
       while ((inputLine = in.readLine()) != null)
           System.out.println(inputLine);
       in.close();
    %>
    

提交回复
热议问题