문제

To get the HttpServletRequest in an interceptor I used below code:

HttpServletRequest request =(HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);

I tried to implement ServletRequestAware in the interceptor but it did not worked.

Are there any better ways to get HttpServletRequest in an Interceptor ?!

도움이 되었습니까?

해결책 2

The servlet stuff you could get referencing servletConfig interceptor. After this interceptor is invoked you could get servlet stuff from ServletActionContext.

HttpServletRequest request = ServletActionContext.getRequest();

다른 팁

You need to use ActionInvocation#getInvocationContext() to retrieve your request.

public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = invocation.getInvocationContext();
    HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
    // ...
}

use

final HttpServletRequest request = (HttpServletRequest) ActionContext.getContext()
                                               .get(ServletActionContext.HTTP_REQUEST);

it worked for me

you will get ActionInvoction try getInvocationContext() it will return instance of "ActionContext" try .get(HTTP_REQUEST); on this.

or

use

ServletActionContext.getRequest()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top