2016-07-15 86 views
0

我使用Spring MVC。我有一個動態的Web項目的EclipseSpring MVC如何從jsp加載js

結構文件夾是

enter image description here

我有以下的JSP actualizarCorreo.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<!DOCTYPE html> 
<html> 
<head> 
<title>EusurveyAdmin menu princiapl</title> 

<script type="text/javascript" src="/resources/js/properties.js"></script> 

<script type="text/javascript"> 
function pruebaB() 
{ 
    alert('en prueba'); 
} 
</script> 
</head> 
<body> 
    <c:set var="pageNumber" value="${pageNumber}" /> 
    <table class="actualizarCorreos"> 

     <tbody> 
     <a href="#" onclick="prueba()"; return false;"> 
      <input type="radio" onclick="prueba()" class="check" id="id1" 
       name="id1" value="true" /> 
      <spring:message code="label.ModificarCorreos" /> 



     </tbody> 
    </table> 

</body> 

在這個JSP我加載另一個JS

<script type="text/javascript" src="/resources/js/properties.js"> 

這是js路徑WebContent/resources/JS。

properties.js是

alert('cargado properties'); 
function checkConfirmationPage() 
{  
    alert('en check'); 
    if ($("#conflink").is(":checked")) 
    {} else {}; 
} 

function prueba() 
{ 
    alert('en prueba'); 
} 

我通話功能prueba從actualizarCorreo.jsp點擊

<input type="radio" onclick="prueba()" class="check" id="id1" 
       name="id1" value="true" /> 
      <spring:message code="label.ModificarCorreos" /> 

我沒有看到警告信息功能prueba一個單選按鈕時。

這是什麼錯誤?

回答

0

試試這個

<script type="text/javascript" src="../resources/js/properties.js"></script> 

或使用以下作爲參考,並找到確切的路徑:

/ = Root directory 
    . = This location 
    .. = Up a directory 
    ./ = Current directory 
    ../ = Parent of current directory 
    ../../ = Two directories backwards 

或者直接獲取上下文路徑來獲取的.js

<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/properties.js" > 
</script> 
+0

我試圖另一個路徑和我得到消息錯誤<未發現與URI [/EusurveyAdminB/correos/corregir/resources/js/properties.js]在DispatcherServlet的名爲'HTTP請求映射eusurveyadmin'>我認爲路徑是正確的 – user3712581

+0

我建議另一種選擇。請嘗試讓我知道。 –

0

在mvc中使用Spring框架時,您必須在您的dispatcher-servlet.xml中提供如下資源路徑。

< mvc:resources mapping="/resources/**" location="/resources/" /> 

然後該文件夾將被允許用於資源。可以調用它們作爲

< script type="text/javascript" src="../../resources/js/properties.js" > 
</ script> 
+0

我已經將此行添加到我的調度程序中。我如何檢查我的js是否已加載? – user3712581

+0

使用瀏覽器手動加載網址。任一網址都會出錯,或者文件不在該路徑。 –

+0

使用工具 - > Web Developer - > Web Console來查看js錯誤。 –