dd

package com.doing360.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

public class UrlUtil {
private static final Logger log = Logger.getLogger(UrlUtil.class);
public static String parseDomain(String url , HttpServletRequest req){

if(url.indexOf("/webPage") > 0){

url = url.substring(0,url.indexOf("/webPage"));
}

if(url.indexOf("/back") > 0){

url = url.substring(0,url.indexOf("/back"));
}

log.info("根据url: "+url+" 开始来截取相应的域名");

String result="";

//局域网开发人员测试登楼的URL:http://www.jsxl2010.cn:8090/eims
if(url.lastIndexOf(":")>"http://a.cn".length())
{
//截取地址的那一小段
String str = url.substring(url.indexOf("//")+2,url.indexOf(req.getContextPath()));
// String str = url.substring(url.indexOf("//")+2,url.indexOf("eims"));
//寻找端口号前的‘:’
str = str.substring(0,str.indexOf(":"));
//截取第一个.
String path = str.substring(0, str.indexOf(".")+1);
//判断前面是否带有'WWW.'
/*
if(path.equals("www.")){
//如果带有就截取
str = str.substring(str.indexOf(".")+1);
}
*/
result=str;
}
else//生产环境访问的URL: http://www.jsxl2010.cn || http://beijing.lanshengroup.com
{
result=url.substring("http://".length(), url.length());

}
log.info("根据 "+result+" 去site表中查询相关数据");
return result;
}

/**
* 测试
* added by fanghui
*/
public static void main(String[] args) {

String url="http://beijing.lanshengroup.com/back/login/doLogin.actionjhkjhjkhkj";
String url8="http://beijing.lanshengroup.com/webPage/show.action?midValue.menuId=d57a3c3c6b8345549a0f";
if(url.indexOf("/webPage") > 0){

url = url.substring(0,url.indexOf("/webPage"));
}

if(url.indexOf("/back") > 0){

url = url.substring(0,url.indexOf("/back"));
}
System.out.println(url);
}

}

你可能感兴趣的:(dd)