ServletActionContext getAction 方法 returns 空
ServletActionContext getAction method returns null
我正在使用一个 servlet 过滤器,我正在尝试获取与当前请求关联的操作。
我的过滤器的相关部分:
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
}
我的问题是 action
最终为空。两个上下文变量都填充了一个值,但由于某种原因它找不到操作。有任何想法吗?谢谢!
当控制通过 ActionServlet 时,ServletActionContext 被初始化并且所有必需的变量都被正确填充。
过滤器在 ActionServlet 之前执行,并且在过滤器方法中创建对象未设置 Action
这是主要原因,因为 ServletActionContext 的一些 getter 方法 returns 空值,因为它没有通过 ActionServlet,因此所有属性都没有初始化。
我正在使用一个 servlet 过滤器,我正在尝试获取与当前请求关联的操作。
我的过滤器的相关部分:
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
}
我的问题是 action
最终为空。两个上下文变量都填充了一个值,但由于某种原因它找不到操作。有任何想法吗?谢谢!
当控制通过 ActionServlet 时,ServletActionContext 被初始化并且所有必需的变量都被正确填充。
过滤器在 ActionServlet 之前执行,并且在过滤器方法中创建对象未设置 Action
这是主要原因,因为 ServletActionContext 的一些 getter 方法 returns 空值,因为它没有通过 ActionServlet,因此所有属性都没有初始化。