【问题标题】:JQuery 1.8.1 TypeError: d is undefined When Using Spring Web MVC + Apache Tiles + JSPXJQuery 1.8.1 TypeError: d is undefined When Using Spring Web MVC + Apache Tiles + JSPX
【发布时间】:2012-08-28 01:07:15
【问题描述】:

我是 JSPX 和 Tiles 的新手。我的瓷砖定义(Tiles 2.2)是:

<tiles-definition>
  <definition name="default" template="/WEB-INF/layouts/test.jspx" preparer="com.test.MenuPreparer">
  </definition>
</tiles-definition>

test.jpsx的内容是:

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:tiles="http://tiles.apache.org/tags-tiles"
  xmlns:c="http://java.sun.com/jsp/jstl/core"
  xmlns:jsp="http://java.sun.com/JSP/Page"    
  xmlns:spring="http://www.springframework.org/tags">     
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<spring:url value="/scripts/jquery-1.8.1.min.js" var="jqURL" />

<script type="text/javascript" src="${jqURL}"><jsp:text /></script> 
</head>

<body>
<h1>TEST!</h1>
</body>
</html>

在我的servlet-context.xml 中,我已包含资源位置:

<resources location="/resources/scripts/" mapping="/scripts/**" />

当我尝试查看页面是 Firefox 14.0.1 时,我在错误控制台中发现以下内容:

TypeError: d is undefined
http://localhost:8080/test/scripts/jquery-1.8.1.min.js

当我在 IE9 中查看同一页面时,我在 IE 控制台中收到以下消息:

SCRIPT5007: Unable to get value of the property 'style': object is null or undefined
jquery-1.8.1.min.js, line 2 character 19451

JQuery 不能在两种浏览器中运行。

但是当我在独立的 HTML 中包含相同的 JQuery 脚本(未部署在 tc Server 中)时,我在浏览器控制台中没有收到错误消息并且 JQuery 正在工作。

使用 Spring Web MVC + Apache Tiles + JSPX 时如何让 JQuery 工作?

【问题讨论】:

    标签: jquery spring-mvc tiles


    【解决方案1】:

    阅读Why does my simple strict XHTML file give errors when I include jquery?后,我在test.jspx中添加了以下行:

    <jsp:output doctype-root-element="html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" omit-xml-declaration="yes" /> 
    

    它现在正在工作。

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-02
      • 1970-01-01
      • 2021-04-22
      相关资源
      最近更新 更多