Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Play2-子域_Java_Routing_Playframework_Playframework 2.0_Subdomain - Fatal编程技术网

Java Play2-子域

Java Play2-子域,java,routing,playframework,playframework-2.0,subdomain,Java,Routing,Playframework,Playframework 2.0,Subdomain,我想创建一个类似stackexchange的网络,只包含子域 比如说 subdomain1.test.com subdomain2.test.com subdomain3.test.com subdomain4.test.com 我还想在一个应用程序中拥有所有网站,这样我可以更轻松地扩展和服务它们 在游戏2中我该怎么做 我可以在路由中指定子域吗 伪码 GET subdomain1/ controllers.Application.in

我想创建一个类似stackexchange的网络,只包含子域

比如说

subdomain1.test.com
subdomain2.test.com
subdomain3.test.com
subdomain4.test.com
我还想在一个应用程序中拥有所有网站,这样我可以更轻松地扩展和服务它们

在游戏2中我该怎么做

我可以在
路由
中指定子域吗

伪码

GET     subdomain1/                           controllers.Application.index()
GET     subdomain2/                           controllers.Application.index()

它将不起作用:如果
路由器
包含两条具有相同类型和目标操作的路由,它将只使用第一条。对于最快的解决方案,您只需创建一个或多个包装方法,该方法将执行您需要的操作,并在视图/控制器级别使用它们:

路线

GET   /home    controllers.Application.index
应用程序控制器

public static String linkMeta(play.api.mvc.Call path) {
    return "http://meta.domain.tld" + path;
}
模板示例:

<a href='@Application.linkMeta(routes.Application.index)'>Absoulte URL link to meta's index</a>
URL: http://meta.domain.tld/home

<a href='@routes.Application.index'>Relative URL to meta's index</a>
URL: /home

网址:http://meta.domain.tld/home
URL:/home

没有,我搜索了它,但找不到有关此主题的任何信息。我甚至不知道如何开始。我有一个后续问题。假设用户访问url
subdomain2.test.com
。play如何知道应该调用哪个函数?(我希望有一个应用程序来处理不同的网站)它将调用相同的路径:ie
GET/controllers.Application.index
-在index()方法中,您可以检查它是哪个域,并为元域或主域等呈现其他输出。顺便说一句,我真的怀疑堆栈交换是否是单个应用程序。