복붙노트

[SPRING] JSP 페이지에서 렌더링되지 않은 스크립트 태그 (Spring + Tiles + JSPX 사용)

SPRING

JSP 페이지에서 렌더링되지 않은 스크립트 태그 (Spring + Tiles + JSPX 사용)

각자 모두,

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>

boby 속성은 openid-selector가있는 양식을 포함하는 jspx 페이지 인 register.jspx에서 재정의됩니다. 리소스 폴더도 매핑되었습니다.

<?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 태그 또는 뭔가 빠졌습니다.

해결법

  1. ==============================

    1.스크립트 태그에 내용이없는 경우 일부 브라우저에서 문제가 발생하기 때문에이 형식의 Java Script 태그를 사용하십시오.

    스크립트 태그에 내용이없는 경우 일부 브라우저에서 문제가 발생하기 때문에이 형식의 Java Script 태그를 사용하십시오.

    <spring:url value="/resources/js/openid-jquery.js" var="openid-jquery_url" />
    <script src="${openid-jquery_url}" type="text/javascript"><!-- required for FF3 and Opera --></script>
    

    또는 더 "안전"

    <script src="${openid-jquery_url}" type="text/javascript"><!-- required for FF3 and Opera --><jsp:text> </jsp:text></script>
    

    이는 jspx 파서가 태그를 최소화하지 못하게하기 때문입니다.

  2. ==============================

    2.Javascript 태그의 한 가지 문제점은 닫는 태그가 있어야한다는 것이고 마지막에 />를 사용하여 바로 가기를 할 수 없다는 것입니다.

    Javascript 태그의 한 가지 문제점은 닫는 태그가 있어야한다는 것이고 마지막에 />를 사용하여 바로 가기를 할 수 없다는 것입니다.

    틀렸어 :