网站seo技术能不能赚钱免费下优化大师
如果可以,请您发布完整的处理程序或处理程序初始化.但我会猜测答案.
我有一种感觉,你的POST请求实际上是通过302重定向的,所以处理程序正确地接收它作为GET请求.
默认情况下,带有“/ app”上下文的Jetty ContextHandler实际上会将任何请求重定向到“/ app”到“/ app /”,请查看setAllowNullPathInfo.
所以你有2个可能的解决方案,在你的ContextHandler上调用setAllowNullPathInfo(true),或者将客户端上的post url更改为HttpPost post = new HttpPost(“http://10.0.2.2:8080/app/”);
它可能会帮助您在jetty上启用RequestLogs,请参阅Jetty/Tutorial/RequestLog
使用以下服务器,您可以通过请求日志查看/ app请求与/ app /之间的区别.
public class RequestLogPost {
public static class PostHandler extends ContextHandler {
public PostHandler() {
setContextPath("/app");
// setAllowNullPathInfo(true); // enable to see difference in request handling
}
@Override
public void doHandle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
System.out.println(request.getMethod());
response.setStatus(HttpStatus.OK_200);
baseRequest.setHandled(true);
}
}
public static void main(String[] args) throws Exception {
Server server = new Server(5555);
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(new PostHandler());
handlers.addHandler(new DefaultHandler());
handlers.addHandler(createRequestLogHandler());
server.setHandler(handlers);
server.start();
server.join();
}
private static RequestLogHandler createRequestLogHandler() {
final int RETAIN_FOREVER = 0; // see RolloverFileOutputStream, 0 == forever.
RequestLogHandler logHandler = new RequestLogHandler();
NCSARequestLog ncsaRequestLog = new AsyncNCSARequestLog("requests.log");
ncsaRequestLog.setAppend(true);
ncsaRequestLog.setExtended(true);
ncsaRequestLog.setLogTimeZone("GMT");
ncsaRequestLog.setRetainDays(RETAIN_FOREVER);
logHandler.setRequestLog(ncsaRequestLog);
return logHandler;
}
}
从请求日志中,将请求发送到“/ app”,结果为302
[30/Jul/2013:12:28:09 +0000] “POST /app HTTP/1.1” 302 0
[30/Jul/2013:12:28:09 +0000] “GET /app/ HTTP/1.1” 200 0
直接请求“/ app /”:
[30/Jul/2013:12:28:16 +0000] “POST /app/ HTTP/1.1” 200 0