有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java springmvc和子域

我目前正在用spring mvc开发一个应用程序,我想使用子域。请确认用户john已在我的应用程序中注册

所以,当用户输入john时。我的应用。com/什么的。我想把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);
    }
}

在我的春天。xml

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

问题是,当我写“john.localhost:8080/Saturn”时,什么都没有发生,子域handler拦截器没有到达。 我是否需要编写其他东西而不是HandlerInterceptorAdapter来处理子域,或者我缺少了什么

我希望澄清。提前谢谢


共 (1) 个答案

  1. # 1 楼答案

    从症状来看,域john.localhost没有指向任何地方

    您需要将其添加到指向127.0.0.1(或类似ipv6)的hosts文件中

    如果是真正的托管域,则需要在dns配置中添加一个指向目标服务器的条目。大多数虚拟主机都会帮你解决这个问题