我想使用RequestDispatcher
将一个来自Servlet的请求转发给Action
RequestDispatcher dispatcher=request.getRequestDispatcher("hello.action");
dispatcher.include(request, response);
它不起作用。我该如何解决这个问题?
我想使用RequestDispatcher
将一个来自Servlet的请求转发给Action
RequestDispatcher dispatcher=request.getRequestDispatcher("hello.action");
dispatcher.include(request, response);
它不起作用。我该如何解决这个问题?
为此,您可能还需要将过滤器设置为在前置机上运行(正如您的代码所示,尽管您声明您想要一个前置机):
<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);
<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>