Mọi người,Thẻ tập lệnh không được hiển thị trong trang JSP (sử dụng Spring + Tiles + JSPX)
Tôi đang gặp phải sự cố lạ bao gồm thẻ tập lệnh trong trang jsp. Trong ba tập lệnh, tôi chỉ bao gồm tập lệnh đầu tiên được kết thúc trong trang cuối cùng. Dưới đây là cách tôi đã xác định bố trí
<?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>
định nghĩa khung nhìn là như sau:
<?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>
đây là mã trang (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>
thuộc tính boby là sau đó được ghi đè trong trang jspx có tên register.jspx chứa biểu mẫu có bộ chọn mở. Các thư mục nguồn lực cũng đã được ánh xạ
<?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>
khi tôi truy cập vào url cho trang đăng ký này, tôi thấy đoạn mã sau (khi kiểm tra các yếu tố thông qua firebug)
<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>
khi tôi xem mã nguồn trang web (unformatted) Tôi thấy các thẻ script không nhìn thấy được; tuy nhiên chúng "không" xuất hiện được định dạng như các thẻ khác trong chế độ xem nguồn xuất hiện.
<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');
});
Và tôi hoàn toàn không có ý tưởng về lý do của hành vi kỳ lạ này.
SOLVED:nhưng một câu hỏi mới bật lên
cảm ơn vì sự giúp đỡ Ralph; Tôi cố gắng gợi ý của bạn
<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>
ám chỉ rằng html (một lần nữa không có ý tưởng tại sao; và tôi hơi quá nhiều tầng để tìm kiếm nó ;-))
<script src="0" type="text/javascript">
<script src="0" type="text/javascript">
nhưng có hình thức này để làm việc
<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>
điều này cho kết quả mong đợi
<script src="/resources/js/openid-jquery.js" type="text/javascript">
<script src="/resources/js/openid-en.js" type="text/javascript">
nó là một vấn đề với mùa xuân: thẻ url hay tôi thiếu một cái gì đó
Tôi không nghĩ rằng đây là nguyên nhân; nhưng bạn có nhận thấy rằng bạn tải biểu mẫu 'jquery-1.7.1.min.js' thành một url khác' http: // code.jquery.com/jquery-1.7.1.min.js' thay vì tài nguyên máy chủ của bạn? – Ralph
yeap Tôi cảm thấy nó không phải là sử dụng tiết kiệm một bản sao cho ứng dụng web của tôi khi chúng tôi có một cách lấy nó từ chế độ lưu trữ của máy chủ jquery. Tôi đã không sử dụng spring: định dạng url cho jquery vì nó đã nhận được bao gồm tốt ở nơi đầu tiên. –