简体   繁体   English

如何在Javascript和Jsp中包含文件?

[英]How to include a file in Javascript and Jsp?

Ok,i know in Php you can use include for a Php file...for example... 好的,我知道在Php中你可以使用include作为Php文件...例如......

include("array.php");

Is there a way to do this in Javascript and Jsp? 有没有办法在Javascript和Jsp中执行此操作?

From what i read i cant use for example include("array.javascript"); 从我读到的我无法使用例如include("array.javascript"); or include("array.jsp"); include("array.jsp");

I want to load the array from a different file and i know how to do it with Php,but not with Javascript or Jsp. 我想从不同的文件加载数组,我知道如何使用Php,但不是使用Javascript或Jsp。 Any help? 有帮助吗?

I think you are a bit confused, JSP is an XML-based language executed at the server side that gets transformed into Java the first time is processed by the servlet container (server) whilst JavaScript is an interpreted language executed by the user's browser, not the server. 我认为你有点困惑,JSP是在服务器端执行的基于XML的语言,第一次由servlet容器(服务器)处理时转换为Java,而JavaScript是由用户的浏览器执行的解释语言,而不是服务器。 PHP is also executed at the server-side and that include function has nothing to do with JavaScript. PHP也在服务器端执行, include函数与JavaScript无关。

Now, to port that behaviour to JSP you would use a JSP tag , more specifically, the <jsp:include /> tag: 现在,要将该行为移植到JSP,您将使用JSP标记 ,更具体地说,使用<jsp:include />标记:

<jsp:include page="array.jsp" />

But if what you are trying to is to link your JSP with a JavaScript file then you should use a better option which consist of using the standard HTML <script> tag: 但是,如果您尝试将JSP与JavaScript文件链接起来,那么您应该使用更好的选项,其中包括使用标准HTML <script>标记:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM