0

まあ、私はhttpサーバーをコーディングする小さなプロジェクトをやっています。コードは

http://code.google.com/p/reactor/

現在のパズルは、java スクリプトと css を使用してページを解析するように求められたときです。http サーバーとして、(別の Web サイトからコピーされた) ページを送信するだけで、不適切に解析されます。私のFirefoxで単純なhtmlページが解析されると、問題はありませんが、より複雑なページ(css + javascript)を解析すると、ページはすべて次のように配線されます:

ボトム:10px;}ボディ>div#divToplayerSmall{position:fixed;} クレイジーワン |

HTMLのソースコードは次のとおりです。

clientWidth:document.body.clientWidth)+(ignoreMe2=document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft))+'px');top:expression((0-divToplayerSmall.offsetHeight+(document. documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight)+(ignoreMe=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop))+'px');}varisTopTrans=(ToplayerBigPath .indexOf("transparent")>-1)?false:true;varisRemTrans=(ToplayerSmallPath.indexOf("transparent")>-1)?false:true;vartop1session=3;vartop2session=5;InitToplayer(isTopTrans,isRemTrans) ;window.onload=StartToplayer;window.onload=StartToplayer;https:/ クレイジーワン | documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft))+'px');top:expression((0-divToplayerSmall.offsetHeight+(document.documentElement.clientHeight?document.documentElement.clientHeight:document.body. clientHeight)+(ignoreMe=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop))+'px');}varisTopTrans=(ToplayerBigPath.indexOf("transparent")>-1)?false: true;varisRemTrans=(ToplayerSmallPath.indexOf("transparent")>-1)?false:true;vartop1session=3;vartop2session=5;InitToplayer(isTopTrans,isRemTrans);window.onload=StartToplayer;https://www.youtube.com/playlist? list... |ONETV |ビッグワン |テレビ番組 | クレイジーワン | documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft))+'px');top:expression((0-divToplayerSmall.offsetHeight+(document.documentElement.clientHeight?document.documentElement.clientHeight:document.body. clientHeight)+(ignoreMe=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop))+'px');}varisTopTrans=(ToplayerBigPath.indexOf("transparent")>-1)?false: true;varisRemTrans=(ToplayerSmallPath.indexOf("transparent")>-1)?false:true;vartop1session=3;vartop2session=5;InitToplayer(isTopTrans,isRemTrans);window.onload=StartToplayer;https://www.youtube.com/playlist? list... |ONETV |ビッグワン |テレビ番組 | クレイジーワン | offsetHeight+(document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight)+(ignoreMe=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop))+'px');} varisTopTrans=(ToplayerBigPath.indexOf("透明")>-1)?false:true;varisRemTrans=(ToplayerSmallPath.indexOf("透明")>-1)?false:true;vartop1session=3;vartop2session=5;InitToplayer( isTopTrans,isRemTrans);window.onload=StartToplayer;window.onload=StartToplayer;https://support.microsoft.com/ja-jp/live/live|oneבסלוללס|ONETV |גליצ'ים |BigONE| クレイジーワン | offsetHeight+(document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight)+(ignoreMe=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop))+'px');} varisTopTrans=(ToplayerBigPath.indexOf("透明")>-1)?false:true;varisRemTrans=(ToplayerSmallPath.indexOf("透明")>-1)?false:true;vartop1session=3;vartop2session=5;InitToplayer( isTopTrans,isRemTrans);window.onload=StartToplayer;window.onload=StartToplayer;https://support.microsoft.com/ja-jp/live/live|oneבסלוללס|ONETV |גליצ'ים |BigONE| クレイジーワン | indexOf("transparent")>-1)?false:true;varisRemTrans=(ToplayerSmallPath.indexOf("transparent")>-1)?false:true;vartop1session=3;vartop2session=5;InitToplayer(isTopTrans,isRemTrans); window.onload=StartToplayer;https:/ クレイジーワン | indexOf("transparent")>-1)?false:true;varisRemTrans=(ToplayerSmallPath.indexOf("transparent")>-1)?false:true;vartop1session=3;vartop2session=5;InitToplayer(isTopTrans,isRemTrans); window.onload=StartToplayer;https:/ クレイジーワン |

כותרותאחרונותצפובמייקללואיסמנצחבתחרותההטבעותבגמרהתיכונים
19/01/07 19:30

אליכהןלשחקניולקראתבני-יהודה:תיראומהאסוליןעשהלמכביחיפה
19/01/07 18:43

ליגתהעלבכדורסל:המשחקיםחוזריםליוםראשון
19/01/07 17:41

דעה:שחרפארכבריכולהלהתמודדעםשחקניותצמרת
19/01/07 16:49

ארצית:הפועלר"גניצחהאתהשקמה/ רמתחן1:2、גםראשל"צנ "ですצנצנ19/ 01/
07 16:45

拍。洞窟、שדשד2.52.5°מ耳19/01/07
16:37 :30אתאת業者、するまっている、ללאג '−℃ בנするか19/01/07 14:45ピンジング0











19/01/07 13:46



varswfPeleSmall=newSWFObject("http://images.one.co.il/images/PeleEmulator/emulator_pelephone_01a.swf","peleSmall",160,470,"6","#FFFFFF"); swfPeleSmall.addParam("品質","高");swfPeleSmall.addParam("wmode","透明");swfPeleSmall.write("divPeleSmall");varswfPeleBig=newSWFObject("http://images.one.co. il/images/PeleEmulator/emulator_pelephone_02d.swf","peleBig",400,470,"6","#FFFFFF");swfPeleBig.addParam("品質","高");swfPeleBig.addParam("wmode","透明");swfPeleBig.write("divWithBig");


פאר:לא:לאלא:לאלא
するとに、1つの1つのמ業者のעברבמעברבמするとかするげするげ





מאתשמאתשון19/01/20077:26
שחרפאררשמשחרפאררשמ業者(ששすると)

コタロコ、ש業者、רלערךלפנです。

コタネズマギפס業者、מערכ業者、拍。

פארפארי−すると、するまっています(16が)(16が)、שםתפג原拍お愛なしです。

פאאממהל-

(Firefox およびページ ソース html でのページ プレゼンテーションの一部のみ)

なぜそれが起こっているのですか?http 応答の midding は何ですか?

StringBuffer tResponse = new StringBuffer();
        tResponse.append("HTTP/1.1 200 OK\n");
    tResponse.append("Date: "+new Date().toString() +'\n');
    tResponse.append("server: http-reactor/0.1-dev\n");
    tResponse.append("last-Modified:"+ d.toString() +'\n');
    tResponse.append("Content-Type: text/html; charset=windows-1255\n");
    tResponse.append("Accept-Language: he; q=1.0, en; q=0.5:);
    tResponse.append("Content-Length: "+tFileContent.length()+'\n');
    tResponse.append('\n');
    tResponse.append(tFileContent);

    public StringBuffer FetchData(String FileName) throws FileNotFoundException{
    StringBuffer tFileContent = new StringBuffer();
    if (FileName.contains("../"))
        throw new SecurityException();
    if (FileName.equals("/"))
        FileName = "\\index.html";
    FileName.replace('/', '\\');
    File f = new File(_root + FileName);
    Scanner scanner = new Scanner(f);
    while(scanner.hasNext())
        tFileContent.append(scanner.next());
    return generateResponse(tFileContent,f.lastModified());
}

private StringBuffer generateResponse(StringBuffer tFileContent, long l) {
    StringBuffer tResponse = new StringBuffer();
    Date d = new Date(l);
    tResponse.append("HTTP/1.1 200 OK\n");
    tResponse.append("Date: "+new Date().toString() +'\n');
    tResponse.append("server: http-reactor/0.1-dev\n");
    tResponse.append("last-Modified:"+ d.toString() +'\n');
    tResponse.append("Content-Type: text/html; charset=windows-1255\n");
    tResponse.append("Accept-Language: he; q=1.0, en; q=0.5:);
    tResponse.append("Content-Length: "+tFileContent.length()+'\n');
    tResponse.append('\n');
    tResponse.append(tFileContent);
    return tResponse;
}
4

3 に答える 3

1

なぜ最初にファイルをスキャンする必要があるのですか。正しいエンコーディング(この例ではwindows-1255)で入力ストリームを開き、コンテンツをストリーミングするだけです。

ところで。HTTPサーバーを作成している場合は、文字列を処理しないことに注意する必要があります。したがって、StringBufferはとにかく良い選択ではありません

于 2011-01-01T18:00:05.877 に答える
1

jspページで応答コンテンツタイプをUTF-8に設定してみてください。メタコンテンツタグが役立ちます。

response.setContentType('utf-8');

tResponse.append("Content-Type: text/html; charset=utf-8\n");

于 2011-01-02T04:18:00.720 に答える
0

content-type ヘッダーを正しく設定する必要があるのでしょうか? また、StringBuffer を使用すると、画像を読み込むときに問題が発生します。

于 2011-01-01T18:28:22.923 に答える