简体   繁体   English

spring-mvc和子域

[英]spring-mvc and subdomains

I'm currently developing an application with spring-mvc and I would like to work with subdomains. 我目前正在使用spring-mvc开发应用程序,并且希望使用子域。 Supose that the user john is registered in my app. 假设用户john在我的应用程序中注册。

So, when the user types john.myapp.com/something. 因此,当用户键入john.myapp.com/something时。 I want to stored john in someplace (don't know where) and redirect to the controller that listen "something". 我想将john存储在某个地方(不知道在哪里),然后重定向到监听“某物”的控制器。 I Hope to be clear. 我希望清楚。

I wrote this interceptor: 我写了这个拦截器:

public class SubdomainHandlerInterceptor extends HandlerInterceptorAdapter  {


    @Override
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {

        System.out.println(request.getServletPath());
        return super.preHandle(request, response, handler);
    }
}

In my spring-servlet.xml 在我的spring-servlet.xml中

<mvc:interceptors>
    <bean class="ar.com.saturn.core.interceptor.SubdomainHandlerInterceptor"> </bean>
</mvc:interceptors>

The problem is that when I wrote "john.localhost:8080/Saturn" nothings happens the SubdomainHandlerInterceptor is not reached. 问题是当我写“ john.localhost:8080 / Saturn”时,什么都没有发生,没有到达SubdomainHandlerInterceptor。 Do i have to write something else instead of a HandlerInterceptorAdapter to work with subdomains, or am I missing something?. 我是否必须编写其他内容而不是HandlerInterceptorAdapter才能与子域一起使用,还是我缺少某些内容?

I hope to be clear. 我希望清楚。 Thanks in advance. 提前致谢。

Judging from the symptoms the domain john.localhost doesn't point anywhere. 从症状来看,域john.localhost没有指向任何地方。

You need to add it to the hosts file pointing to 127.0.0.1 (or ipv6 equivalent). 您需要将其添加到指向127.0.0.1 (或ipv6等效文件)的hosts文件中。

In case of real, hosted domains you need to add an entry to your dns configuration pointing to the destination server. 如果是真实的托管域,则需要在dns配置中添加一个指向目标服务器的条目。 Most virtualhosts take care of that for you. 大多数虚拟主机都会为您解决这一问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM