根据子域名/域名更改索引页面 [英] Change of Index page based on subdomain/domain name

查看:158
本文介绍了根据子域名/域名更改索引页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题和我的想法很模糊,因为我还处于设计阶段。我只想知道一些事情,以便在问题上以及如何/在何处着手解决问题。

Problem and my idea on it is just vague as I'm still in design phase. I just wanted to know something to get a head start on the problem and how/where to proceed to solve it.

问题部分:

有一个使用struts-2 JSP / servlet构建的Web应用程序,URL mywebapp.com
要求是每个客户都可以使用他们的子域访问此 mywebapp.com ,例如 webapp.abc.com, myapp.xyz.com,等我必须根据域名进行过滤,以便为他们提供自定义的登录页面。我已将其域名保存在数据库中,以映射需要在自定义登录页面上显示的详细信息。

There's one web app built using struts-2 JSP/servlet, with the URL mywebapp.com. The requirement is every client can access this mywebapp.com using their subdomain, like webapp.abc.com, myapp.xyz.com, etc. I have to filter based on the domain name to give them a customized login page. I have saved their domain name in the database to map their details that need to be displayed on customized login page.

我认为他们会将 mywebapp.com 的I​​P地址提供给他们的子域名注册表,这样它就会登陆 mywebapp.com,但是从这里开始,我如何过滤自定义登录页面的域/子域名?

What I have thought is they will give the IP address of mywebapp.com to their subdomain registry so it will land on mywebapp.com, but from here, how can I filter the domain/subdomain for a customized login page?

任何可能的方式开始这将是赞赏。

Any possible way to start on this will be appreciated.

推荐答案

我建议使用过滤器。使用过滤器,您可以独立于控制器处理对您的应用程序的任何请求。

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.

更新:有关于Struts的更多文档2个拦截器,可以起到类似的作用: http://java.dzone.com / articles / struts2-tutorial-part-57

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];
     }
 }

如果从数组末尾开始,知道倒数第二个域始终是二级域(SLD),而倒数第三个域是第三级子域所在的位置。

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.

这篇关于根据子域名/域名更改索引页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆