我正在 JSP 页面中编写一个 servlet 来显示请求的网页。我做了相当多的“谷歌搜索”,其中大多数人建议使用 BufferedReader。下面我有从 JSP 页面获取请求的 url 并且 servlet 显示页面的代码。
但是,在运行此程序时,我从 servlet 得到空白。谁能建议我在这段代码中做错了什么?
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String server = request.getParameter("browsebox");
URL url = new URL(server);
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(), "UTF-8"));
String inputLine;
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
a.append(inputLine);
in.close();
PrintWriter out = response.getWriter();
out.println(a);
// String output= a.toString();
//System.out.println(output);
}