Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript文件未加载_Javascript_Jsf 2 - Fatal编程技术网

javascript文件未加载

javascript文件未加载,javascript,jsf-2,Javascript,Jsf 2,正在尝试从我的页面导入我的js文件 我的页面位于webcontent/mydomain/templates/page.xhtml 我的js位于webcontent/mydomain/test/scripts 在page.xhtml中 <script type="text/javascript" src="../test/scripts/test.js"></script> 但剧本仍然没有被挑选出来 谁能告诉我需要如何在src中给出路径。试试这个: <scrip

正在尝试从我的页面导入我的js文件

我的页面位于
webcontent/mydomain/templates/page.xhtml

我的js位于
webcontent/mydomain/test/scripts

在page.xhtml中

<script type="text/javascript" src="../test/scripts/test.js"></script>

但剧本仍然没有被挑选出来

谁能告诉我需要如何在src中给出路径。

试试这个:

<script src="/test/scripts/test.js"></script>

前提是
webcontent
是公共web内容的根目录,因此
/mydomain
也是一个公共文件夹,因此您的JavaScript可以通过
http://localhost:8080/context/mydomain/test/scripts/test.js
,假设域为
http://localhost:8080
和上下文路径
/context
,则应执行以下操作:

<script src="#{request.contextPath}/mydomain/test/scripts/test.js"></script>


这将生成一个具有动态内联上下文路径的域相对URL,这比摆弄
。/
会使URI相对于当前请求URI(如您在浏览器的地址栏中所看到的)要健壮得多而不是像许多初学者错误地假设的那样,指向模板文件的物理位置。

&尝试完整路径
尝试:
您确实需要显示您的代码。您确定要从服务器而不是文件打开页面吗?我使用的是JSF2.0,所以只有xhtml。我也不能使用h:outputScript,因为我不能将js放在resources文件夹中。下面的代码还能工作吗?“…我正在使用JSF2.0,所以只有xhtml。而且我不能使用h:outputScript,因为我不能将js放在resources文件夹中。下面的代码还能工作吗?”