我想像这样使用这样的方式将请求从Servlet转发到ActionRequestDispacher
RequestDispatcher dispatcher=request.getRequestDispatcher("hello.action");
dispatcher.include(request, response);
它不工作。我该如何解决这个问题?
我想像这样使用这样的方式将请求从Servlet转发到ActionRequestDispacher
RequestDispatcher dispatcher=request.getRequestDispatcher("hello.action");
dispatcher.include(request, response);
它不工作。我该如何解决这个问题?
为了做到这一点,您可能还需要将过滤器设置为在 FORWARD 上运行(并且如您的代码所示,包括,尽管您声明您想要一个 FORWARD):
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher> <!-- If you want includes as well -->
</filter-mapping>
使用 servlet 中的代码
getServletContext().getRequestDispatcher("/hello.action").forward(request, response);
您还配置了 struts2 过滤器以接受转发请求
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>