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

(这条文章已经被阅读了 52 次) 时间:2001-04-11 09:01:00 来源:szxyz (zjxyz) 原创-IT

HttpRequest.java
——————————————
package http;
import java.io.*;

public class HttpRequest{

public String HttpMethomd;
String Requesturl;
String RequestSouc;
String HttpVersion;
String GetRequest;
int statuscode=200;
String[] ClientReceive=null;

HttpRequest(String[] ClientReceive ){
this.ClientReceive=ClientReceive;
ConstrueRequest();
}//end HttpRequest()

void ConstrueRequest(){
try{
RequestSouc=ClientReceive[0];
int indexpre,indexnex;
if (ClientReceive[0]==””){
statuscode=404;
return;}

indexpre=ClientReceive[0].indexOf(‘ ‘);
HttpMethomd=ClientReceive[0].substring(0,indexpre);
indexpre++;
indexnex=ClientReceive[0].indexOf(‘ ‘,indexpre);

Requesturl = ClientReceive[0].substring(indexpre,indexnex);

if ( Requesturl.lastIndexOf(‘?’) != -1 ){
RequestSouc=Requesturl.substring( 0,Requesturl.lastIndexOf(‘?’) );
GetRequest=Requesturl.substring( Requesturl.lastIndexOf(‘?’)+1,Requesturl.length() );
}else{
GetRequest=””;
RequestSouc=Requesturl;
}

HttpMethomd.toUpperCase();

}catch (StringIndexOutOfBoundsException e){
HttpMethomd=”GET”;
statuscode=500;
System.out.println(“err1″);
return;}
catch (NullPointerException e){
HttpMethomd=”GET”;
statuscode=500;
System.out.println(“err2”);
return;}

}//end ConstrueRequest()

}//end class HttpRequest

作者:XYZ※版权所有,
转载请注明来源
【CGI编程设计室】
http://zjxyz.yeah.net