Dewfy
Dewfy

Reputation: 23614

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>
    <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?

Upvotes: 1

Views: 2173

Answers (3)

BalusC
BalusC

Reputation: 1108642

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.

Upvotes: 2

Nate
Nate

Reputation: 2456

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>

Upvotes: 0

Will Hartung
Will Hartung

Reputation: 118603

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.

Upvotes: 0

Related Questions