如何从ServletRequestEvent获取URL特定的详细信息和请求类型(GET,POST,PUT)?

时间:2016-12-08 10:50:15

标签: java servlets servlet-listeners

我正在实现ServletRequestListener并重写其方法requestInitialized和requestDestroyed。当调用requestDestroyed时,我想知道请求是否是GET / POST请求以及随之发送的参数等详细信息。该方法应该是什么?

public void requestDestroyed(ServletRequestEvent event) {
    ServletRequest s = event.getServletRequest();
    //use this to get those details

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作。

public void requestDestroyed(ServletRequestEvent event) {
    ServletRequest s = event.getServletRequest();
    HttpSevletRequest request = (HttpServletRequest) s;

    String method = request.getMethod();
    Map<String,String[]> parameters = request.getParameterMap();
}