0
votes

Can the url-pattern in a servlet filter-mapping point to a servlet in another domain?

<filter>
    <filter-name>CORSFilter</filter-name>
    <filter-class>com.example.CORSFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CORSFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

In the url-pattern putting /* would make this filter apply to all servlets in the application. Is there a way to apply filter for servlets in another domain/application? If so, what is the url pattern I should use.

I tried putting the full path to the domain name and servlet, but an error was thrown and my application didn't start up.

1
No, this is not possible. It is expected only local URL mapping there.Leos Literak

1 Answers

1
votes

No. The filter mapping only specifies a URL pattern for URLs that hit your application.

If you mean you have your application running on multiple domains and you want the filter to only be mapped for a specific domain, there is not a way to do this with the filter mapping. If you mean you want to have the filter inside your application affect a servlet outside of your web application, this is not possible.