这个答案是对发生的聊天的回应。
以下是我的 servlet 代码
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().println("Hello World");
response.getWriter().flush();
response.getWriter().close();
}
以下是我的连接代码,它可以工作。
public static void main(String[] args) throws IOException {
System.setProperty("http.proxyHost", "proxy.***.com");
System.setProperty("http.proxyPort", "####");
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("user",
"pwd".toCharArray()));
}
};
Authenticator.setDefault(authenticator);
URL url = new URL( "http://localhost:8080/ImageCanvas/Servlet2" );
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while((line=br.readLine())!= null){
System.out.println(line);
System.out.flush();
}
br.close();
}