Tomcat Server.xml有如下配置<Host name="www.fly.cn"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false" URIEncoding="gbk2312">
        <alias>fly.cn</alias>    
        <alias>fly.com.cn</alias>
        <alias>www.fly.com.cn</alias>
        <alias>flying.com</alias>
        <alias>www.flying.com</alias>
</Host>
开启的是80端口,网站程序全放在ROOT文件夹下,现在想将在地址栏内输入flying.com或者www.flying.com的访问请求都重定向到www.flying.com/abc/index.jsp上而不影响其他请求,请问如何实现。我现在的办法是使用过滤器,不过没有成功,希望大家能帮帮忙,在此谢谢了!给源码的分多~~

解决方案 »

  1.   

    多定义几项
    <Host name="flying.com" appBase="webapps">
       
         <Context path="/" docBase="tomcat_home/webapps/abc/index.jsp" /></Host><Host name="www.flying.com" appBase="webapps">
       
         <Context path="/" docBase="tomcat_home/webapps/abc/index.jsp" /></Host>
      

  2.   

    http://sookk8.blog.51cto.com/455855/114120
      

  3.   

    不写filter好像是没办法实现的。
      

  4.   

    这个不是在dns服务中设置的吗?
    域名映射,域名转向
      

  5.   

    5楼那文章不知道在哪转的,google出来的基本上就是那一篇。
      

  6.   

    我filter写的不成功,能否赐教个?
      

  7.   

    由于是动态IP,所以用花生壳做了域名解析,所有通过以上域名访问的请求最终路由到了服务器所在的路由器上,路由器已经做了映射,将这些请求映射到服务器80端口,不知道你说的dns服务怎么设置,能否详细点?
      

  8.   

    花生壳功能不是很懂,但是能绑定一个域名就可以绑定多个域名
    在域名管理中有应该有重定向,把fly.cn 和 fly.com 重定向到花生壳的域名上
      

  9.   


    我没有写过,但是我认为没有什么难度。
    直接取得请求的完整url,然后解析域名,然后重定向。但是配置肯定不是你写的那样。
      

  10.   


    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;public class URLFilter implements Filter{ public void destroy() {

    } public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpServletRequest=(HttpServletRequest)request;
            HttpServletResponse httpServletResponse = (HttpServletResponse) response;
            String url=httpServletRequest.getHeader("referer");
            System.out.println(url);
            if("http://flying.com/".equals(url)||"http://www.flying.com/".equals(url)){
             httpServletResponse.sendRedirect("abc/index.jsp");
             return;
            }
            chain.doFilter(request, response);
    }
    public void init(FilterConfig arg0) throws ServletException {

    }}这个filter不成功,没有达到预期效果。另外我有个疑问,在IE中输入www.flying.com,为什么后台输出很多http://www.flying.com/而不是一个?
      

  11.   

     httpServletResponse.sendRedirect("abc/index.jsp");
     再获取的URL真确的前提下,这里的路径写绝对路径。 httpServletResponse.sendRedirect("http://ip地址或则域名/abc/index.jsp");
      

  12.   

    问题是获取正确之后,重定向陷入死循环,后台一直输出 
    url
    url
    .
    .
    .
    不知道为什么
      

  13.   


    Filter里面怎么会死循环呢? 我没有碰到过这种问题呀。都跳转了,还会循环?
      

  14.   

    我想filter是不是拦截/过滤数据报的?
      

  15.   

    filter里面
    请求重定向
    httpServletResponse.sendRedirect("abc/index.jsp");
      

  16.   

    咋用TOMCAT做HTTP服务器呢~
    用APACHE HTTPD+TOMCAT
    用专业的好不好
      

  17.   

            String url=httpServletRequest.getHeader("referer");
            System.out.println(url);
            if("http://flying.com/".equals(url)||"http://www.flying.com/".equals(url)){
                httpServletResponse.sendRedirect("abc/index.jsp");
                return;
            }看看你的逻辑,对么?
    http://www.flying.com/abc/index.jsp是不是又能满足"http://www.flying.com/".equals(url)?
      

  18.   

    谢谢提醒,我去apache 官网看看。
      

  19.   

    最简单方法就是在根目录下的index.jsp文件中
    用request.getServerName();取得域名地址,在判断是不是相应的域名
    在用reqeust.sendRedirect("abc/index.jsp"); 
    不就完了嘛
      

  20.   

    单独的TOMCAT每个域名各自绑定一次应该是可以的,不过我没用过,我用APACHE+TOMCAT