最后完善的JAVA WEB服务器源代码(7) - 我的代码 - szxyz

(这条文章已经被阅读了 38 次) 时间:2001-04-12 08:52:52 来源:szxyz (zjxyz) 原创-IT

HttpResponse.java
————————————————————–
package http;
import java.io.*;
import container.servlet.*;
import container.staticsou.*;

public class HttpResponse{

HttpRequest httprequest;
static byte readfromfile[];
HttpStatusCodes HttpStatus=new HttpStatusCodes();
String HttpStatusMsg=null;
PrintStream sendmsg=null;

HttpResponse(PrintStream sendmsg,HttpRequest httprequest){

this.httprequest=httprequest;
this.sendmsg=sendmsg;

}//end HttpResponse()

public void Toclient(){

if ( httprequest.HttpMethomd.equals(“GET”) ){
dealGet();}
if( httprequest.HttpMethomd.equals(“POST”) ){
dealPost();}

if (httprequest.statuscode!=200){
sendmsg.print(HttpStatus.toString(httprequest.statuscode)+”

“);
sendmsg.print( HttpStatus.toString(httprequest.statuscode));
return;
}

if (httprequest.RequestSouc.startsWith(“/servlet/”)){ //是否是 servlet 的目录映射
ServletHold servlethold= new ServletHold(httprequest);
servlethold.LoadClasses(httprequest.RequestSouc);
return;
}//end if

if ( httprequest.HttpMethomd.equals(“GET”) ){
dealLocalFile FileHandle= new dealLocalFile(httprequest.RequestSouc);

if (FileHandle.FileExists()==0){
sendmsg.print(HttpStatus.toString(404)+”

“);
sendmsg.print( HttpStatus.toString(404));
return;
}

//byte[] msg = FileHandle.ReadLocalFile();
byte[] msg = FileHandle.GetContent();

sendmsg.print(HttpStatus.toString(200)+”
“);
sendmsg.print(jwsconf.GetMime(httprequest.RequestSouc)+”

” );
sendmsg.write(msg,0,msg.length);

}//end if

return;
}

public void dealGet(){
return;
}

public void dealPost(){
sendmsg.print( HttpStatus.toString(405)+”

“);
sendmsg.print( HttpStatus.toString(httprequest.statuscode));
return;}

}

作者:XYZ※版权所有,

转载请注明来源
【CGI编程设计室】
http://zjxyz.yeah.net