如何在jsp中使用http请求来请求和获取网页 [英] How to request and get a webpage using http request in jsp
本文介绍了如何在jsp中使用http请求来请求和获取网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取xml页面(我是指从Web服务获得的REST API),解析该页面并将其显示在我的网站中(使用jsp)?
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?
推荐答案
我没有完整的答案,但是至少这里是如何获取网页的方法.我正在尝试做类似的事情,所以当我有更多的时候会回来的.
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();
%>
这篇关于如何在jsp中使用http请求来请求和获取网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文