开发者

Struts2 combine with domain specific servlet

I have struts2 web application. Right now I need embed with help of iframe some functionality from stand-alone servlet. But according to following rule, servlet is never get calling.

<filter-mapping>
    &开发者_运维问答lt;filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Unfortunately I cannot change it to /prefix/*

So does anybody know how to resolve it?


Filters are called in the order as they're definied in web.xml. I'd create a filter with a more specific url-pattern in the front of the Struts2 filter and then let this filter forward the request to the servlet in question instead of continuing the filter chain. E.g.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
    request.getRequestDispatcher("/servletURL").forward(request, response);
}

Map this on the same url-pattern as the servlet, i.e. /servletURL and put it before the Struts2 filter in the web.xml.


Try looking at this: Struts 2 Web XML

There is a question: "Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7)" which should ideally help. In theory you should be able to put your exception in this list, and map your servlet normally.

I won't comment on this design decision for the Struts 2 folks.


We are doing this with struts 2.1.6 defining the struts filter like this:

<filter><!--  struts filter  -->
    <filter-name>strutsFilter</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>strutsFilter</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>

And our other Servlets like this:

<servlet-mapping>
    <servlet-name>SomeOtherServlet</servlet-name>
    <url-pattern>*.yo</url-pattern>
</servlet-mapping>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜