我有一个扩展AbstractHandler的Jetty Handler,从我在线研究可以看出,我应该能够配置它来告诉Jetty处理除post / get之外的动词。我需要配置我的Jetty服务器来处理“补丁”请求,现在jetty返回405。
答案 0 :(得分:1)
你可以这样做:
package com.test.jetty.handler;
// imports
public class MyRequestHandler extends AbstractHandler {
@Override
public void handle(String path, Request request, HttpServletRequest serveletRequest, HttpServletResponse servletResponse)
throws IOException, ServletException {
String requestMethod = request.getMethod().toUpperCase();
try {
switch (requestMethod) {
case "POST":
// do post logic
System.out.println("post");
break;
case "GET":
// do get logic
System.out.println("get");
break;
case "PATCH":
// do patch logic
System.out.println("patch");
break;
// so on.....
default:
// do default
}
} catch (Exception e) {
e.printStackTrace();
}
}
}