ServletActionContext getAction method returns null

此生再无相见时 提交于 2019-12-11 04:24:44

问题


I am using a servlet filter where I am trying to get the action associated with the current request.

Relevant sections of my filter:

private ServletContext context;

public void init(FilterConfig config) throws ServletException {
    this.context = config.getServletContext();
}

protected void doFilter(HttpServletRequest request, HttpServletResponse response,
        FilterChain chain) throws IOException, ServletException {

    ServletActionContext actionContext = new ServletActionContext(context, request, response);

    Action action = actionContext.getAction();
    // action == null

}

My problem is that action ends up being null. Both of the context variables get populated with a value, but for some reason it cant find the action. Any ideas? Thanks!


回答1:


ServletActionContext are initialised and all required variable are filled properly when control pass through ActionServlet.

Filter are executed before ActionServlet and and Creating object in filter method doesnt set Action

That is the main reason because of that some getter method of ServletActionContext returns null values because it doesn't gone through ActionServlet and hence all properties are not initialised.



来源:https://stackoverflow.com/questions/43072965/servletactioncontext-getaction-method-returns-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!