如何在JSP页面中加载远程JavaScript文件

如何在JSP页面中加载远程JavaScript文件,javascript,jquery,jsp,Javascript,Jquery,Jsp,我正在尝试从远程API执行一些脚本。 当我上传到我的服务器时,.js不会执行。尽管在localhost中,它们工作正常 这是我的JSP: <!DOCTYPE html> <%@ page import="client.Errors"%> <html lang="en"> <head> <meta charset="UTF-8"/> <title>Phill Login-In</title&

我正在尝试从远程API执行一些脚本。 当我上传到我的服务器时,
.js
不会执行。尽管在
localhost
中,它们工作正常

这是我的JSP:

<!DOCTYPE html>
<%@ page import="client.Errors"%>
<html lang="en">
   <head>
      <meta charset="UTF-8"/>
      <title>Phill Login-In</title>
      <link rel="stylesheet" href="./style.css"/>
      <script type="text/javascript">
         function formSubmit(form) {
             setTimeout(function () {
                 form.submit();
             },
             3000);// 3 seconds
             return false;
         }
      </script>
   </head>
   <%
      String reqId = request.getParameter("request_id");       
      %>
   <body>
      <form name="phillLogin" id="formData" action="/oam/server/auth_cred_submit" method="POST" onsubmit="return formSubmit(this);">
         <div class='login'>
            <div class='login_title'>
               <%String err = request.getParameter("p_error_code");%>
               <%if (err==null){%>
               <h3>
                  <b>Login to your account</b>
               </h3>
               <% }%>
               <%if(err!=null)
                  {
                     Errors errors=new Errors();
                     Object simpleMessage[][]=(Object[][])errors.getContents(); 
                     String temp[]=err.split("-");
                     int pos=Integer.parseInt(temp[1]);
                  %>
               <h3>
                  <%=simpleMessage[pos-1][1].toString()%>
               </h3>
               <%}%>
            </div>
            <div class='login_fields'>
               <div class='login_fields__user'>
                  <div class='icon'>
                     <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/user_icon_copy.png'/>
                  </div>
                  <input placeholder='Username' type="text" name="username" id="user" style="font-size:medium;"/>
                  <div class='validation'>
                     <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/tick.png'/>
                  </div>
               </div>
               <div class='login_fields__password'>
                  <div class='icon'>
                     <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/lock_icon_copy.png'/>
                  </div>
                  <input placeholder='Password' type="password" name="password" id="pass"
                     style="font-size:medium;"/>
                  <div class='validation'>
                     <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/tick.png'/>
                  </div>
               </div>
               <div class='login_fields__submit'>
                  <input type="submit" value="Log In" id="Submit" style="font-size:small;"/>
               </div>
            </div>
            <%
               if(reqId != null && reqId.length() > 0) { %>
            <input type="hidden" name="request_id" value="=reqId%>"/>
            <% } %>
         </div>
      </form>
      <div class='authent'>
         <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/puff.svg' />
         <p>Proccessing Data...</p>
      </div>
      <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
      <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
      <script src="./script.js"></script>
      <script></script>
   </body>
</html>

Phill登录
功能表单提交(表单){
setTimeout(函数(){
表单提交();
},
3000);//3秒
返回false;
}
登录到您的帐户
0) { %>
正在处理数据

请注意,这些脚本无法从服务器远程访问


如何将这些脚本正确加载到文件中?

我尝试在
中包含以下内容,但似乎不起作用:



<script>
   (function (d, s, id) {
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {
         return;
     }
     js = d.createElement(s);
     js.id = id;
     js.onload = function () {
         // remote script has loaded
     };
     js.src = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js";
     fjs.parentNode.insertBefore(js, fjs);
   }
   (document, 'script', 'first'));
</script>
<script>
   (function (d, s, id) {
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {
         return;
     }
     js = d.createElement(s);
     js.id = id;
     js.onload = function () {
         // remote script has loaded
     };
     js.src = "http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js";
     fjs.parentNode.insertBefore(js, fjs);
   }
   (document, 'script', 'first'));
</script>



(功能(d、s、id){
var js,fjs=d.getElementsByTagName[0];
if(d.getElementById(id)){
返回;
}
js=d.createElement;
js.id=id;
js.onload=函数(){
//远程脚本已加载
};
js.src=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js";
fjs.parentNode.insertBefore(js,fjs);
}
(文件‘脚本’、‘第一’);
(功能(d、s、id){
var js,fjs=d.getElementsByTagName[0];
if(d.getElementById(id)){
返回;
}
js=d.createElement;
js.id=id;
js.onload=函数(){
//远程脚本已加载
};
js.src=”http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js";
fjs.parentNode.insertBefore(js,fjs);
}
(文件‘脚本’、‘第一’);

您是否尝试在控制台中查找错误,然后用谷歌搜索错误?控制台中有什么日志,浏览器控制台中有错误吗?@PhillAlexakis-首先,您需要确定它们没有加载的原因。使用浏览器中的调试工具。查看“网络”选项卡以检查JS的请求和响应。查看控制台对于错误。@PhillAlexakis-所以请尝试按照我在前面的评论中给出的建议进行操作,并从另一端进行调试。@PhillAlexakis-好吧,因为您现在混淆了jQuery和jQuery UI URL…可能不是…但是其他的都是相同的-是的。但是您说它不起作用,所以其他的都是不相等的…所以您需要要调试它!你是否尝试在控制台中查找错误,然后用谷歌搜索它们?控制台中有什么日志,浏览器控制台中有错误吗?@PhillAlexakis-首先你需要确定它们没有加载的原因。使用浏览器中的调试工具。查看“网络”选项卡以检查JS的请求和响应。查看CoNSLE查找错误。@PhillAlexakis-所以请尝试按照我在前面的评论中给出的建议进行操作,并从另一端进行调试。@PhillAlexakis-好吧,因为您现在混淆了jQuery和jQuery UI URL…可能不是…但是其他的都是一样的-是的。但是您说它不起作用,其他的都不一样…所以您需要调试它!


<script>
   (function (d, s, id) {
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {
         return;
     }
     js = d.createElement(s);
     js.id = id;
     js.onload = function () {
         // remote script has loaded
     };
     js.src = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js";
     fjs.parentNode.insertBefore(js, fjs);
   }
   (document, 'script', 'first'));
</script>
<script>
   (function (d, s, id) {
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {
         return;
     }
     js = d.createElement(s);
     js.id = id;
     js.onload = function () {
         // remote script has loaded
     };
     js.src = "http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js";
     fjs.parentNode.insertBefore(js, fjs);
   }
   (document, 'script', 'first'));
</script>