我通过servlet将文件上传到我的服务器上。 它一直很好,直到今天下午,突然间我开始得到
java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8282
我一直在使用tomcat 7进行应用程序,并且工作正常。 我不确定服务器内发生了什么事情,或者问题究竟发生在哪里。
我试过了:
JAVA_TOOL_OPTIONS
添加到系统变量。我无法找到解决问题的其他可行方案。如果可能,请建议并提供见解。
以下是我的应用程序中的代码:(客户端代码):
private URLConnection getServletConnection() throws MalformedURLException,
IOException {
// Config
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestMethod("POST");
servletConnection.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + this.boundary);
servletConnection.setRequestProperty("Connection", "Keep-Alive");
servletConnection.connect();
return servletConnection;
}
private boolean onSendData(String fileEntry) {
try {
// Send data to the servlet
HttpURLConnection servletConnection = (HttpURLConnection) getServletConnection();
DataOutputStream dataOutputStream = new DataOutputStream(
servletConnection.getOutputStream());
final FileInputStream fileInputStream = new FileInputStream(
...
// send multipart form data necesssary after file data
dataOutputStream.writeBytes(lineEnd);
dataOutputStream.writeBytes(twoHyphens + boundary + twoHyphens
+ lineEnd);
// Receive result from servlet
InputStream inputStream = servletConnection.getInputStream();
ObjectInputStream objectInputStream = new ObjectInputStream(
inputStream);
String result = (String) objectInputStream.readObject();
objectInputStream.close();
inputStream.close();
dataOutputStream.flush();
dataOutputStream.close();
fileInputStream.close();
} catch (java.net.MalformedURLException mue) {
mue.printStackTrace();
System.out
.println("Invalid serlvetUrl, error: " + mue.getMessage());
errorLabel.setText(mue.getMessage());
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
System.out.println("Couldn't open a URLConnection, error: "
+ ioe.getMessage());
errorLabel.setText(ioe.getMessage());
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception caught, error: " + e.getMessage());
errorLabel.setText(e.getMessage());
}
return fileUploaded;
}
这就是我所看到的错误(当我在我的IDE中运行代码时):
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8282/UploadFile/upload
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at com.FileUpload.onSendData(FileUpload.java:317)
... 4 more
奇怪的是,当我在网络浏览器上运行它(作为一个签名的JAR文件运行)时,我在java控制台中看到以下错误(这是一个小程序)。
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
Couldn't open a URLConnection, error: Connection refused: connect