Change of Index page based on subdomain/domain name

我是研究僧i 提交于 2019-12-06 05:27:30

I would suggest using a Filter. With a filter, you can process any requests to your application independent of the controllers.

For instance, if you wanted to redirect to a different page based on subdomain, your filter could manage this, either as a filter that processes before the controller call or after the controller call.

UPDATE: There is more documentation on Struts 2 Interceptors, which can serve a similar purpose: http://java.dzone.com/articles/struts2-tutorial-part-57

 String domain = "";
 String subdomain = "";

 String url = request.getRequestURL();
 String[] parts = url.split(".");

 // subdomain.domain.com  0, 1, 2
 // subdomain1.subdomain2.domain.com  0, 1, 2, 3
 domain = (parts.length - 2 > -1) ? parts[1] : parts[];

 for(int i = parts.length - 1; i >= 0; i--) {
     if(i == parts.length - 2) {
         domain = parts[i];
     }
     if(i == parts.length - 3) {
         subdomain = parts[i];
     }
 }

If you start from the end of the array, you know that the 2nd to last is always the second-level domain (SLD) and the 3rd from last is where the third level subdomains will be.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!