日期:2014-05-16 浏览次数:20356 次
?HttpServletRequest rq = (HttpServletRequest) request;
//?String[] serverNameList = serverName.split(",");
?((HttpServletResponse)response).setStatus(301);
?if(!(rq.getQueryString()==null)&&!rq.getQueryString().equals("")){
??((HttpServletResponse)response).setHeader("Location", "http://www."+serverName.split(",")[0]+"/"+rq.getRequestURI()+"?"+rq.getQueryString());
?}else{
??((HttpServletResponse)response).setHeader("Location", "http://www."+serverName.split(",")[0]+"/"+rq.getRequestURI());
?}
?
?((HttpServletResponse)response).setHeader( "Connection", "close" );?
?
其中的serverName在web.xml中配置
?
<filter>
??<filter-name>CharacterEncodingFilter</filter-name>
??<filter-class>
???cn.com.innet.util.SetCharacterEncodingFilter
??</filter-class>
??<init-param>
???<param-name>encode</param-name>
???<param-value>GBK</param-value>
??</init-param>
??<init-param>
???<param-name>forceEncoding </param-name>
???<param-value>true </param-value>
??</init-param>
??<init-param>
???<param-name>serverName </param-name>
???<param-value>hopechart.com</param-value>
??</init-param>
?</filter>