Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.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 多重<;脚本>;标签和<;!——//FF3和Opera需要-->;_Javascript_Html_Spring Mvc - Fatal编程技术网

Javascript 多重<;脚本>;标签和<;!——//FF3和Opera需要-->;

Javascript 多重<;脚本>;标签和<;!——//FF3和Opera需要-->;,javascript,html,spring-mvc,Javascript,Html,Spring Mvc,我使用SpringRoo生成了一个基本的web项目。该UI基于JSP,具有平铺布局。查看默认布局代码,我注意到标记的定义如下: <script src="${dojo_url}" type="text/javascript" ><!-- //required for FF3 and Opera --></script> <script src="${spring_url}" type="text/javascript"><!-- //requ

我使用SpringRoo生成了一个基本的web项目。该UI基于JSP,具有平铺布局。查看默认布局代码,我注意到标记的定义如下:

<script src="${dojo_url}" type="text/javascript" ><!-- //required for FF3 and Opera --></script>
<script src="${spring_url}" type="text/javascript"><!-- //required for FF3 and Opera --></script>
<script src="${spring_dojo_url}" type="text/javascript"><!-- //required for FF3 and Opera --></script>

如果我去掉脚本标记之间的注释,Firefox中生成的HTML包含第一个标记,但不包含其他标记。如果我将注释放回结果HTML中,则是正确的

我的问题是:为什么会有这种行为?

script标记的()没有提到它需要包含任何类型的数据内容。这是一个浏览器问题(如注释所暗示的),还是一个JSP或Spring问题

返回HTML和浏览器输出
无论是否有注释,cURL结果看起来都一样:

<head>
    <meta name="generator" content="HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <meta content="IE=8" http-equiv="X-UA-Compatible" />
    <link href="/student-cloud-app/static/styles/login.css;jsessionid=FFED09C524087878AEF09142A6A6F375" media="screen" type="text/css" rel="stylesheet" />
    <link href="/student-cloud-app/static/images/favicon.ico;jsessionid=FFED09C524087878AEF09142A6A6F375" rel="SHORTCUT ICON" />
    <script type="text/javascript" src="/student-cloud-app/resources/dojo/dojo.js;jsessionid=FFED09C524087878AEF09142A6A6F375"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring.js;jsessionid=FFED09C524087878AEF09142A6A6F375"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring-Dojo.js;jsessionid=FFED09C524087878AEF09142A6A6F375"></script>
    <title>
      Sample App
    </title>
</head>
<head>
    <meta name="generator" content="HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <meta content="IE=8" http-equiv="X-UA-Compatible" />
    <link href="/student-cloud-app/static/styles/login.css" media="screen" type="text/css" rel="stylesheet" />
    <link href="/student-cloud-app/static/images/favicon.ico" rel="SHORTCUT ICON" />
    <script type="text/javascript" src="/student-cloud-app/resources/dojo/dojo.js"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring.js"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring-Dojo.js"></script>
    <title>
      Sample App
    </title>
</head>

示例应用程序
事实上,无论评论是否存在,从Firefox查看源代码看起来都是一样的:

<head>
    <meta name="generator" content="HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <meta content="IE=8" http-equiv="X-UA-Compatible" />
    <link href="/student-cloud-app/static/styles/login.css;jsessionid=FFED09C524087878AEF09142A6A6F375" media="screen" type="text/css" rel="stylesheet" />
    <link href="/student-cloud-app/static/images/favicon.ico;jsessionid=FFED09C524087878AEF09142A6A6F375" rel="SHORTCUT ICON" />
    <script type="text/javascript" src="/student-cloud-app/resources/dojo/dojo.js;jsessionid=FFED09C524087878AEF09142A6A6F375"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring.js;jsessionid=FFED09C524087878AEF09142A6A6F375"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring-Dojo.js;jsessionid=FFED09C524087878AEF09142A6A6F375"></script>
    <title>
      Sample App
    </title>
</head>
<head>
    <meta name="generator" content="HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <meta content="IE=8" http-equiv="X-UA-Compatible" />
    <link href="/student-cloud-app/static/styles/login.css" media="screen" type="text/css" rel="stylesheet" />
    <link href="/student-cloud-app/static/images/favicon.ico" rel="SHORTCUT ICON" />
    <script type="text/javascript" src="/student-cloud-app/resources/dojo/dojo.js"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring.js"></script>
    <script type="text/javascript" src="/student-cloud-app/resources/spring/Spring-Dojo.js"></script>
    <title>
      Sample App
    </title>
</head>

示例应用程序
但是,如果我打开Firebug并检查HTML树,删除注释后,只有一个脚本元素,它包含一条错误消息:

未能为以下对象加载源:

我得到空白页面而不是登录表单。如果我将注释放回,Firebug将报告所有脚本标记,没有错误,页面将显示登录表单。禁用Firebug对页面是否正确呈现没有影响;无注释=空白页,注释=正确呈现的页

更新: 返回的实际标记是自动关闭的。HTML tidy正在解决这个问题。自动关闭脚本标记实际上是导致问题的原因

更新2:示例HTML 以下是在浏览器中使用的带有正确关闭的脚本标记的HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <meta content="text/html; charset=UTF-8"
    http-equiv="Content-Type" />
    <meta content="IE=8" http-equiv="X-UA-Compatible" />
    <link href="/student-cloud-app/static/styles/login.css"
    media="screen" type="text/css" rel="stylesheet" />
    <link href="/student-cloud-app/static/images/favicon.ico"
    rel="SHORTCUT ICON" />
    <script type="text/javascript" src="/static/scripts/ajax.js"></script>
    <script type="text/javascript" src="/static/scripts/jquery-1.4.2.min.js"></script>
    <title>Student Cloud</title>
  </head>
  <body>
    <div id="container">
      <form method="POST"
      action="/student-cloud-app/static/j_spring_security_check"
      name="f">
        <table align="center" class="table">
          <tr>
            <td>
              <label for="j_username">User name:</label>
            </td>
            <td>
              <input name="j_username" type="text"
              id="j_username" />
            </td>
          </tr>
          <tr>
            <td>
              <label for="j_password">Password:</label>
            </td>
            <td>
              <input name="j_password" type="password"
              id="j_password" />
            </td>
          </tr>
          <tr>
            <td class="login_button" colspan="2">
              <input value="Login" type="submit" />
            </td>
          </tr>
        </table>
      </form>
    </div>
  </body>
</html>

学生云
用户名:
密码:
以下是完全相同的HTML,除了带有自动关闭脚本标记:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <meta content="text/html; charset=UTF-8"
    http-equiv="Content-Type" />
    <meta content="IE=8" http-equiv="X-UA-Compatible" />
    <link href="/student-cloud-app/static/styles/login.css"
    media="screen" type="text/css" rel="stylesheet" />
    <link href="/student-cloud-app/static/images/favicon.ico"
    rel="SHORTCUT ICON" />
    <script type="text/javascript" src="/static/scripts/ajax.js" />
    <script type="text/javascript" src="/static/scripts/jquery-1.4.2.min.js" />
    <title>Student Cloud</title>
  </head>
  <body>
    <div id="container">
      <form method="POST"
      action="/student-cloud-app/static/j_spring_security_check"
      name="f">
        <table align="center" class="table">
          <tr>
            <td>
              <label for="j_username">User name:</label>
            </td>
            <td>
              <input name="j_username" type="text"
              id="j_username" />
            </td>
          </tr>
          <tr>
            <td>
              <label for="j_password">Password:</label>
            </td>
            <td>
              <input name="j_password" type="password"
              id="j_password" />
            </td>
          </tr>
          <tr>
            <td class="login_button" colspan="2">
              <input value="Login" type="submit" />
            </td>
          </tr>
        </table>
      </form>
    </div>
  </body>
</html>

学生云
用户名:
密码:

保存为.html文件时,第一个示例在浏览器中正确显示,第二个则不正确。

是否正确删除注释?可能是您删除了太多或太少的评论开始/结束。你有这个吗

<script src="${dojo_url}" type="text/javascript"></script>
<script src="${spring_url}" type="text/javascript"></script>
<script src="${spring_dojo_url}" type="text/javascript"></script>


确保删除相同数量的
块。

是否正确删除注释?可能是您删除了太多或太少的评论开始/结束。你有这个吗

<script src="${dojo_url}" type="text/javascript"></script>
<script src="${spring_url}" type="text/javascript"></script>
<script src="${spring_dojo_url}" type="text/javascript"></script>


确保删除相同数量的
块。

注释就位后,生成的HTML中的
标记的结束标记为
。当这些注释被删除时,标签是自动关闭的


显然,大多数浏览器中都有自动关闭的脚本标记。感谢thenduks为我指出了正确的方向。

当注释就位时,生成的HTML中的
标记有一个结束标记
。当这些注释被删除时,标签是自动关闭的


显然,大多数浏览器中都有自动关闭的脚本标记。感谢thenduks为我指出了正确的方向。

你能粘贴实际输出(用
curl
或类似的工具而不是浏览器检索)吗?我从未见过或听说过这种行为。我同意调查问题的方法是查看实际生成的HTML。您是否可以粘贴实际输出(使用
curl
或类似工具而不是浏览器检索)?我从未见过或听说过这种行为。我同意调查问题的方法是查看实际生成的HTML。注释被正确删除。你能粘贴最后得到的HTML块吗?代码已粘贴在上面。也许我只是错过了一些愚蠢的东西。注释被正确地删除了。你能粘贴最后得到的HTML块吗?代码已经粘贴在上面了。也许我只是错过了一些愚蠢的事情,不是真的。每个支持XHTML的浏览器都正确地支持自动关闭脚本标记。我在FF3和IE8中都验证过,在其他条件相同的情况下,空脚本标记可以工作,但自动关闭脚本标记不能。我不是说XHTML不支持任何自动关闭标记,我是说它不支持自动关闭脚本标记。您可能无法使用真正的XHTML环境。确保DOCTYPE是正确的,这样就不会触发HTML和/或怪癖模式。每个支持XHTML的浏览器都正确地支持自动关闭脚本标记。我在FF3和IE8中都验证过,在其他条件相同的情况下,空脚本标记可以工作,但自动关闭脚本标记不能。我不是说XHTML不支持任何自动关闭标记,我是说它不支持自动关闭脚本标记。您可能无法使用真正的XHTML环境。确保DOCTYPE正确,这样就不会触发HTML和/或怪癖模式。