Weather information pl
Bos.write ("Content type:? image/jpg\r\n。 getBytes());
bos.write(("Content-Length:"+length+"\r\n ")。 getBytes());
Bos.write ("Last modified:?" +? New? Date (). toGMTString()+"\r\n ")。 getBytes());
bos.write("\r\n "。 getBytes()); //The end of the response header and the beginning of the response body bos are directly socket.getOutputStream (). Other codes are the same as yours. The latest version of FF test shows jpg images normally.
Complete document of the test
Import? Java . io . *;
Import? Java . net . *;
Import? Java . util . date;
Public? Class? SocketHttp{
Public? Static electricity Invalid? Main (string? Args[]) throw? Abnormal {
New? SocketHttp()。 test();
}
Public? Invalid? Test () throw? Abnormal {
ServerSocket? ser=new? server socket(8080);
New? WriteThread(ser.accept())。 start();
}
Class? WriteThread? Extension? Thread {
Public? WriteThread(Socket? sk){
this.sk = sk
}
Socket? sk;
Public? Invalid? run(){
Try {
OutputStream? Bos. =? sk . get output stream(); //There is a graph first.
Documents? img? =? New? file(" imag 0693 _ resize . jpg ");
InputStream? Is it? =? New? file inputstream(img);
Dragon? Length? =? is . available(); //Response status line
Bos . write(" HTTP/ 1. 1? 200? Ok \ r \ n. getBytes()); //response header start
Bos.write ("Content type:? image/jpg\r\n。 getBytes());
bos.write(("Content-Length:"+length+"\r\n ")。 getBytes());
Bos.write ("Last modified:?" +? New? Date (). toGMTString()+"\r\n ")。 getBytes());
bos.write("\r\n "。 getBytes()); //The response header ends and the response body begins.
Bos . flush();
int? len
byte[]? Buffer? =? New? byte[ 1024];
What time? ((len? =? is.read(buffer))? & gt? 0)? {
Bos.write (buffer, 0,? len);
}
Bos . flush();
bos.write("\r\n\r\n "。 getBytes()); //End of response body
Bos . close();
}catch (exception? For example) {
ex . printstacktrace();
}
}
}
}