views:

45

answers:

3

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>
    <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? Thanks in advance!

A: 

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.

Will Hartung
@Will, thanks. Just for debug purpose I've put this parameter to follow: <constant name="struts.action.excludePattern" value=".*"/> - in any way my servlet doesn't get control :(
Dewfy
A: 

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>
Nate
@Nate, yes, I know this way, but note my restriction "Unfortunately I cannot change it to /prefix/*".Because yours way will change all urls in the system
Dewfy
A: 

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.

BalusC