最近在看《how tomcat works》,在第一章模拟服务器时有一个错误,不知道如何解决。
当我在浏览器中输入localhost:8080/yes时,无论是firefox还是chrome,都会发送多次请求,下面是我服务器打印出得请求信息
[code="java"]
start
accepted
GET /yes HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
start
accepted
GET /favicon.ico HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
start
accepted
GET /favicon.ico HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
start
accepted
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.stillness.character1.Request.parseURI(Request.java:97)
at com.stillness.character1.Request.getURI(Request.java:105)
at com.stillness.character1.HttpServer.await(HttpServer.java:55)
at com.stillness.character1.HttpServer.main(HttpServer.java:70)
[/code]
分别请求 /yes /favicon.ico /favicon.ico
其中请求/yes时,返回404错误;而请求/favicon.ico时,我的目录下没有该图标,返回的应该也是404;
第四次请求,根本不存在请求头文件什么的,似乎只是建立连接,然后不发送信息就断掉了。
错误在chrome中每次都会出,在firefox中偶尔会出。
---------------源文件就是下面的了