如何将来自 servlet 的请求转发到 struts2 的操作?

2022-01-16 00:00:00 dispatcher java servlets struts2

我想像这样使用 RequestDispacher 将请求从 Servlet 转发到 Action

I want to forward a request from Servlet to Action like this using RequestDispacher like this

RequestDispatcher dispatcher=request.getRequestDispatcher("hello.action");
dispatcher.include(request, response);

它不工作.我该如何解决这个问题?

It's not working. How can I resolve this problem?

推荐答案

为了做到这一点,您可能还需要将过滤器设置为在 FORWARD 上运行(并且如您的代码所示,包括,尽管您声明您想要一个 FORWARD):

In order to do this you may also need to set the filter to run on FORWARD (and INCLUDE as your code shows, although you state you want a 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>

相关文章