|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我实在想不明白java的机制,为什么非要那么蛋疼,在同一个平台下重复编译。asp.net|web|站点|转换很常常利用到的一个功效,但在在网上却一向没有找到相干的办理办法,明天借着项目使用到的时机写了两个将相对路径转换为假造路径封装好的办法
将Web站点下的相对路径转换为相对指定页面的假造路径
/**////<summary>
///将Web站点下的相对路径转换为相对指定页面的假造路径
///</summary>
///<paramname="page">以后页面指针,通常是this</param>
///<paramname="specifiedPath">相对路径</param>
///<returns>假造路径,型如:../../</returns>
publicstaticstringConvertSpecifiedPathToRelativePathForPage(Pagepage,stringspecifiedPath)
{
//根目次假造路径
stringvirtualPath=page.Request.ApplicationPath;
//根目次相对路径
stringpathRooted=HostingEnvironment.MapPath(virtualPath);
//页面假造路径
stringpageVirtualPath=page.Request.Path;
if(!Path.IsPathRooted(specifiedPath)||specifiedPath.IndexOf(pathRooted)==-1)
{
thrownewException(string.Format(""{0}"是假造路径而不是相对路径!",specifiedPath));
}
//转换成绝对路径
//(测试发明,pathRooted在VS2005自带的服务器跟在IIS下根目次大概假造目次运转仿佛纷歧样,
//有此中央前面会加"",有些则不会,为保险起见判别一下)
if(pathRooted.Substring(pathRooted.Length-1,1)=="")
{
specifiedPath=specifiedPath.Replace(pathRooted,"/");
}
else
{
specifiedPath=specifiedPath.Replace(pathRooted,"");
}
stringrelativePath=specifiedPath.Replace("","/");
string[]pageNodes=pageVirtualPath.Split(/);
//减往最初一个页面和后面一个""值
intpageNodesCount=pageNodes.Length-2;
for(inti=0;i<pageNodesCount;i++)
{
relativePath="/.."+relativePath;
}
if(pageNodesCount>0)
{
//假如存在"..",则把最后面的"/"往失落
relativePath=relativePath.Substring(1,relativePath.Length-1);
}
returnrelativePath;
}
第二个办法明显是从第一个办法中的前部分抽掏出来的,以是懒得往增加相干正文:P
将Web站点下的相对路径转换为假造路径
/**////<summary>
///将Web站点下的相对路径转换为假造路径
///注:非Web站点下的则不转换
///</summary>
///<paramname="page">以后页面指针,通常是this</param>
///<paramname="specifiedPath">相对路径</param>
///<returns>假造路径,型如:~/</returns>
publicstaticstringConvertSpecifiedPathToRelativePath(Pagepage,stringspecifiedPath)
{
stringvirtualPath=page.Request.ApplicationPath;
stringpathRooted=HostingEnvironment.MapPath(virtualPath);
if(!Path.IsPathRooted(specifiedPath)||specifiedPath.IndexOf(pathRooted)==-1)
{
returnspecifiedPath;
}
if(pathRooted.Substring(pathRooted.Length-1,1)=="")
{
specifiedPath=specifiedPath.Replace(pathRooted,"~/");
}
else
{
specifiedPath=specifiedPath.Replace(pathRooted,"~");
}
stringrelativePath=specifiedPath.Replace("","/");
returnrelativePath;
}
将假造路径转相对路就没甚么好说的了,HttpRequest.MapPath办法专门干这事
中间码是基于一个虚拟机器。源代码是最高层的,理论上从源代码开始直接编译成本地码能提供最大优化的。而中间码只能是转译成本地码,效率上难免受到损耗。根据虚拟机器所设定的体系结构的特点,和本地机器的差异的多少。 |
|