我目前正在使用spring-mvc开发一个应用程序,我想使用子域名。假设用户john已在我的应用程序中注册。
因此,当用户键入john.myapp.com/something时。我想在某个地方存储john(不知道在哪里)并重定向到听“某事”的控制器。我希望能够清楚。
我写了这个拦截器:
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);
}
}
在我的spring-servlet.xml中
<mvc:interceptors>
<bean class="ar.com.saturn.core.interceptor.SubdomainHandlerInterceptor"> </bean>
</mvc:interceptors>
问题在于,当我写“john.localhost:8080 / Saturn”时,没有发生SubdomainHandlerInterceptor。 我是否必须编写其他内容而不是HandlerInterceptorAdapter来处理子域名,或者我错过了什么?。
我希望能够清楚。提前谢谢。
答案 0 :(得分:0)
从症状来看,域john.localhost
并未指向任何地方。
您需要将其添加到指向hosts
(或等效的ipv6)的127.0.0.1
文件中。
如果是真实的托管域,则需要在指向目标服务器的dns配置中添加一个条目。大多数虚拟主机都会为您处理这个问题。