使用哪个绝对路径或相对路径? [英] Which one to use absolute or relative path?

查看:103
本文介绍了使用哪个绝对路径或相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Spring MVC开发的Web应用程序. 我有一个jsp页面,使用相同的绝对路径将同一应用程序的页面嵌入到iframe中,如下所示.我将应用程序部署在tomcat中.

I have one web application developed using Spring MVC. I have a jsp page where I am embedding the same application's page into iframe using an absolute path as below. I deploy the app in tomcat.

在选项卡上单击时使用jQuery:

Using jQuery on click of tab:

$('#iframeId').attr('src', 'http://somehost:8080/maApp/somePath.do?paramOne=us');


<iframe id="iframeId" style="width:90%;height:200px;border:0" src=""></iframe> 

以上代码仅在Windows机器中有效,而bu在unix/linux机器(tomcat)中失败.

The above code works only in only windows machine bu fails in unix/linux machine (tomcat).

但是,如果我将其更改为相对路径,则可以在Windows和Unix/Linux中使用.

But if I change it to relative path the it works in both windows and unix/linux.

$('#iframeId').attr('src', 'somePath.do?paramOne=us');

绝对路径或相对路径应该使用哪个?

推荐答案

相对路径是相对于正在调用的文件的实际位置的路径.基本上,相对路径假定该文件位于当前"服务器"/本地服务器".通过使用相对路径,我们甚至可以离线构建我们的网站.可以在将文件上传到服务器上之前对其进行全面测试.例如:"sunlinux \ project1 \ admin \ csv \ updateshi.php".在上面的示例中,我们给出了文件在当前服务器上的实际路径.绝对路径-绝对路径是指使用其完整URl引用Internet上文件的路径.绝对路径告诉浏览器precisley去哪里.示例-http:\ facebook.com \ demouser

A Relative path is a path which is Relative to the actual location of the file that is calling .Basically a relative path assumes that the file is on the "Current server" / "local Server".By using Relative path we can construct our site even offline & can fully test it before uploading files on the server. For Example: "sunlinux\project1\admin\csv\updateshi.php" .In above example we are giving the actual path where is the file is located on the current server. Absolute path -- An Absolute path is a path which refers to a file on the internet using its full URl. Absolute path tells the browser precisley where to go. Example-- http:\facebook.com\demouser

因此,仅用于实时服务器始终是绝对路径.

So just Use for live servers always absolute path.

这篇关于使用哪个绝对路径或相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆