我在嵌入式模式下使用 Jetty 6。我在 ContextHandlerCollection 中有许多 servlet。除了这个问题之外,servlet 在它们不同的 URL 上也能正常工作。
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
HandlerContainer mainhandler = contexts;
Context qxrpc = new Context(contexts,"/api",Context.SESSIONS);
ServletHolder rpcServHolder = new ServletHolder(new FrzRpcServlet());
rpcServHolder.setInitParameter("referrerCheck", "public");
// allows cross-domain calls
qxrpc.addServlet( rpcServHolder, "*.qxrpc");
Context statscontext =new Context(contexts,"/stats",Context.SESSIONS);
ServletHolder statsHolder = new ServletHolder(new FrzStatsServlet());
statsHolder.setInitParameter("restrictToLocalhost", "false");
// allows cross-domain calls
statscontext.addServlet(statsHolder, "/*");
Context hellocontext = new Context(contexts,"/hello", Context.SESSIONS);
hellocontext.addServlet(new ServletHolder(new HelloServlet("HELLO TEST: ")),
"/*");
Context zdbcontext = new Context(contexts,"/zdb", Context.ALL);
ServletHolder zdbHolder = new ServletHolder(new FrzZdbServlet());
statsHolder.setInitParameter("restrictToLocalhost", "false");
// allows cross-domain calls
zdbcontext.addServlet(zdbHolder, "/*");
Context root = new Context(mainhandler,"/",Context.SESSIONS);
root.setResourceBase(docroot);
root.addServlet(DefaultServlet.class, "/");
我知道 POST 请求正在发送到我的服务器。这是一些 ngrep 输出:
T 127.0.0.1:51634 -> 127.0.0.1:8080 [AP]
GET /zdb/test.123:1.1.local1.stringtest HTTP/1.1..Host: 127.0.0.1:8080..Connection: keep-alive..Referer: http://127.0.0.1:8888/GWT_ZDB_editor.html?gwt.codesvr=127.0.0.1:9997..Origin: http://127.0.0.1:8888..User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24..Content-Type: text/plain; charset=utf-8..Accept: */*..Accept-Encoding: gzip,deflate,sdch..Accept-Language: en-US,en;q=0.8..Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3....
##
T 127.0.0.1:8080 -> 127.0.0.1:51634 [AP]
HTTP/1.1 200 OK..Access-Control-Allow-Origin: *..Content-Type: application/json; charset=ISO-8859-1..Content-Length: 124..Server: Jetty(6.1.15)....
##
T 127.0.0.1:8080 -> 127.0.0.1:51634 [AP]
{ "r":0,"D":"test.123:1.1.local1.stringtest","m":"OK","t":0,"p": {"ztype": "STRING", "dat" : { "cp":0, "v": "test12131" }}}
##
不成功的 POST - 报告 200 OK - 但从未到达 servlet
T 127.0.0.1:51634 -> 127.0.0.1:8080 [AP]
OPTIONS /zdb/test.123:1.1.local1.stringtest/put HTTP/1.1..Host: 127.0.0.1:8080..Connection: keep-alive..Referer: http://127.0.0.1:8888/GWT_ZDB_editor.html?gwt.codesvr=127.0.0.1:9997..Access-Control-Request-Method: POST..Origin: http://127.0.0.1:8888..User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24..Access-Control-Request-Headers: content-type..Accept: */*..Accept-Encoding: gzip,deflate,sdch..Accept-Language: en-US,en;q=0.8..Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3....
#
T 127.0.0.1:8080 -> 127.0.0.1:51634 [AP]
HTTP/1.1 200 OK..Allow: GET, HEAD, POST, TRACE, OPTIONS..Content-Length: 0..Server: Jetty(6.1.15)...
.
我无法弄清楚为什么 doPost() 没有被调用,而 doGet() 被调用。有问题的 servlet 是 FrzZdbServlet。
在 Google 上找到了许多线程,但 Jetty 的人只指向示例,而这些示例又只为 Context 示例实现 do doGet()。就像在这里
另外,我从 GWT 代码发布,我使用的是内容类型的应用程序/json。这可能是问题吗?任何指针将不胜感激。