Search code examples
javahttp-redirectsubdomainurl-pattern

Java url-pattern all subdomains redirect


is there any possibility in Java's web.xml of redirect all subdomains to one servlet?

For example:

<url-pattern>*.</url-pattern>

Solution

  • You can definitely do that but I think you would like to define your URL pattern using *.ext or *.* as below:

        <url-pattern>*.*</url-pattern>
    

    This is also used by some populare MVC frameworks such as struts where UL pattern

        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
       </servlet-mapping>
    

    is mapped to Struts controller servlet.