Announcement Announcement Module
Collapse
No announcement yet.
Controller Dispatch based on domain of URL on request Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller Dispatch based on domain of URL on request

    Is it possible to get the DispatcherServlet to dispatch to different Controllers based on the domain of the URL on the request?

    i.e. My site can be accessed via two domains...

    http://mysite.com/
    http://xyz.mysite.com/

    ...and ideally I'd like to have two separate controllers for handling each of the above despite the request path being the same (i.e. / in the above example).

    A quick example:

    @Controller
    public class HomeController {
    ...
    @RequestMapping("/")
    public String showHomePage() {}
    }

    @Controller
    public class XyzHomeController {
    ...
    @RequestMapping("/")
    public String showHomePage() {}
    }

    NB: I'm trying to avoid having to use rewrite rules

    Thanks

    Dan

  • #2
    There's not out-of-the-box handler mapping that do what you expect but for sure you can write your one implementation of org.springframework.web.servlet.HandlerMapping that uses domain names as another way to select a controller/method

    Comment

    Working...
    X