我有Java webserver(沒有標準軟件...自寫)。一切似乎工作正常,但當我嘗試調用包含圖片的頁面時,這些圖片不會顯示。我是否必須將圖像與輸出流一起發送到客戶端?我錯過了一個額外的步驟?當網站從自己寫的網絡服務器調用時沒有顯示圖像
由於有太多的代碼,它張貼在這裏,這裏是一個小的輪廓會發生什麼或應該發生:
1. client logs in
2. client gets a session id and so on
3. the client is connected with an output stream
4. we built the response with the HTML-Code for a certain 'GET'-request
5. look what the GET-request is all about
6. send html response || file || image (not working yet)
這麼多的基本輪廓...
它發送css文件和東西,但我仍然有一個圖像的問題! 有沒有人有想法?如何將圖像從服務器發送到瀏覽器? 謝謝。
我使用charles檢查來自客戶端的請求和來自服務器的響應。它發送的文件(如css或js)很好,但不與圖像:雖然狀態是「200 OK」,傳輸編碼是chunked ...我不知道這意味着什麼!?有人知道嗎?
編輯: 這裏是文件讀取代碼:
try{
File requestedFile = new File(file);
PrintStream out = new PrintStream(this.getHttpExchange().getResponseBody());
// File wird geschickt:
InputStream in = new FileInputStream(requestedFile);
byte content[] = new byte[(int)requestedFile.length()];
in.read(content);
try{
// some header stuff
out.write(content);
}
catch(Exception e){
e.printStackTrace();
}
in.close();
if(out!=null){
out.close();
System.out.println("FILE " + uri + " SEND!");
}
}
catch (/*all exceptions*/) {
// catch it ...
}
全部大寫,真的嗎? – Tim 2009-07-14 07:20:45
響應包含什麼? – cjk 2009-07-14 07:23:21
@ck:響應是html頁面作爲字符串...它通過輸出流發送回客戶端 @Tim:呵呵? – doro 2009-07-14 07:32:44