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上而不影响其他请求,请问如何实现。我现在的办法是使用过滤器,不过没有成功,希望大家能帮帮忙,在此谢谢了!给源码的分多~~
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上而不影响其他请求,请问如何实现。我现在的办法是使用过滤器,不过没有成功,希望大家能帮帮忙,在此谢谢了!给源码的分多~~
<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>
域名映射,域名转向
在域名管理中有应该有重定向,把fly.cn 和 fly.com 重定向到花生壳的域名上
我没有写过,但是我认为没有什么难度。
直接取得请求的完整url,然后解析域名,然后重定向。但是配置肯定不是你写的那样。
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/而不是一个?
再获取的URL真确的前提下,这里的路径写绝对路径。 httpServletResponse.sendRedirect("http://ip地址或则域名/abc/index.jsp");
url
url
.
.
.
不知道为什么
Filter里面怎么会死循环呢? 我没有碰到过这种问题呀。都跳转了,还会循环?
请求重定向
httpServletResponse.sendRedirect("abc/index.jsp");
用APACHE HTTPD+TOMCAT
用专业的好不好
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)?
用request.getServerName();取得域名地址,在判断是不是相应的域名
在用reqeust.sendRedirect("abc/index.jsp");
不就完了嘛
的