How to forward request from servlet to action of struts2?

前端 未结 2 705
你的背包
你的背包 2020-12-05 03:32

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

RequestDispatche         


        
相关标签:
2条回答
  • 2020-12-05 04:02

    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>
    
    0 讨论(0)
  • 2020-12-05 04:20

    Use the code in the servlet

    getServletContext().getRequestDispatcher("/hello.action").forward(request, response);
    

    You have also configure struts2 filter to accept forward requests

    <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>
    
    0 讨论(0)
提交回复
热议问题