大家,腳本標籤
我面臨着一個奇怪的問題,包括在JSP頁面腳本標籤。在這三個劇本中,我只包括第一個在最後一頁中進入的腳本。 這裏如下我是如何定義的佈局
<?xml version="1.0" encoding="UTF-8"?>
<!--$Id$ -->
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="default" template="/WEB-INF/layouts/default.jspx">
<put-attribute name="header" value="/WEB-INF/views/header.jspx" />
<put-attribute name="submenu" value="/WEB-INF/views/submenu.jspx" />
<put-attribute name="body" value="/WEB-INF/views/body.jspx" />
<put-attribute name="footer" value="/WEB-INF/views/footer.jspx" />
</definition>
<definition name="registration" template="/WEB-INF/layouts/registration.jspx">
<put-attribute name="header" value="/WEB-INF/views/header.jspx" />
<put-attribute name="body" value="/WEB-INF/views/body.jspx" />
</definition>
</tiles-definitions>
視圖定義是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition extends="registration" name="register/default">
<put-attribute name="body" value="/WEB-INF/views/register/register.jspx"/>
</definition>
</tiles-definitions>
這裏的頁面代碼(registration.jspx)
<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:c="http://java.sun.com/jsp/jstl/core" version="2.0">
<jsp:output doctype-root-element="HTML" doctype-system="about:legacy-compat" />
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:directive.page pageEncoding="UTF-8" />
<jsp:output omit-xml-declaration="true" />
<head>
<c:url var="rootUrl" value="/resources/" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<link rel="stylesheet" type="text/css" href="/resources/css/screen.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/openid.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/openid-shadow.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"/>
<script type="text/javascript" src="/resources/js/openid-jquery.js"/>
<script type="text/javascript" src="/resources/js/openid-en.js"/>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
openid.init('openid_identifier');
});
//]]>
</script>
<title>Mystery Shopping</title>
</head>
<body>
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="body" />
</body>
</html>
的波比屬性然後在一個名爲register.jspx的jspx頁面中重寫,該頁面包含帶有openid-selector的表單。資源文件夾也被映射
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Scans within the base package of the application for @Components to configure as beans -->
<context:component-scan base-package="vm.brands.controller" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
</beans>
當我訪問URL對該登記頁面我看到下面的代碼(檢查通過螢火元素時)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=8">
<link rel="stylesheet" type="text/css" href="/resources/css/screen.css">
<link rel="stylesheet" type="text/css" href="/resources/css/openid.css">
<link rel="stylesheet" type="text/css" href="/resources/css/openid-shadow.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js">
<title>Mystery Shopping</title>
</head>
當我查看網頁源(無格式)我確實看到了其他不可見的腳本標籤;但是它們「不」顯示爲源視圖中其他標記的格式。
<html version="2.0"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/><meta content="IE=8" http-equiv="X-UA-Compatible"/><link href="/resources/css/screen.css" type="text/css" rel="stylesheet"/><link href="/resources/css/openid.css" type="text/css" rel="stylesheet"/><link href="/resources/css/openid-shadow.css" type="text/css" rel="stylesheet"/><script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"/><script src="/resources/js/openid-jquery.js" type="text/javascript"/><script src="/resources/js/openid-en.js" type="text/javascript"/><script type="text/javascript">
$(document).ready(function() {
openid.init('openid_identifier');
});
我對這種奇怪的行爲的原因絕對沒有想法。
解決:但一個新的問題彈出
感謝您的幫助拉爾夫;我想你的建議
<spring:url value="/resources/js/openid-jquery.js" var="openid-jquery_url"/>
<spring:url value="/resources/js/openid-en.js" var="openid-en_url"/>
<script src="${openid-jquery_url}" type="text/javascript"><jsp:text> </jsp:text></script>
<script src="${openid-en_url}" type="text/javascript"><jsp:text> </jsp:text></script>
呈現HTML(再次沒有想法,爲什麼和我有點過於分層搜索它;-))
<script src="0" type="text/javascript">
<script src="0" type="text/javascript">
但得到這種形式的工作
<c:url var="rootUrl" value="/resources/" />
<script src="${rootUrl}js/openid-jquery.js" type="text/javascript"><jsp:text> </jsp:text></script>
<script src="${rootUrl}js/openid-en.js" type="text/javascript"><jsp:text> </jsp:text></script>
這給預期的輸出
<script src="/resources/js/openid-jquery.js" type="text/javascript">
<script src="/resources/js/openid-en.js" type="text/javascript">
是它與彈簧的一個問題:URL標記或者我失去了一些東西
我不認爲這是原因;但你有沒有注意到你加載了'jquery-1.7.1.min.js'形式的一個不同的URL'http:// code.jquery.com/jquery-1.7.1.min.js'而不是你的服務器資源? – Ralph 2012-02-24 17:47:30
yeap當我們有一種從jquery服務器的託管模式中獲取它的方法時,我覺得將它保存到我的web應用程序是沒有用的。我沒有使用jquery的spring:url格式,因爲它首先被包含在內。 – 2012-02-24 19:20:06