2016-08-22 52 views
0

我在我的春季項目中應用了外部JavaScript,但它不工作。如果我在內部應用JavaScript,那麼它正在工作。也沒有錯誤。外部Javascript無法運行?是否有任何特定的文件夾爲javascript

我的代碼是

loginPage.jsp

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 

<html> 
<head> 
    <title>Spring3Example</title> 
<style> 
    .error { 
     color: #EF1313; 
     font-style: italic; 
    } 
</style> 


<!-- 
<script type="text/javascript"> 

function focusFieldOne() { 
    document.form1.user.focus(); 
    } 


function validateForm() 
{ 
    var str1=new String("filed should not be blank"); 
if(document.form1.user.value=="") 
{ 

    alert(str1.fontcolor("red")); 
    //alert("User Name should not be blank.."); 
document.form1.user.focus(); 
return false; 
} 
else if(document.form1.password.value=="") 
{ 
alert("Password should not be blank"); 
document.form1.password.focus(); 
return false; 
} 
} 

function func1() 
{ 
    //alert("this is final alert"); 
    var user = document.getElementById('user').value; 
     var pass = document.getElementById('password').value; 

     if(/[^a-zA-Z0-9]/.test(user)) { 
      alert('Input is not alphanumeric'); 
      return false; 
     } 



     if(/[^a-zA-Z0-9]/.test(pass)) { 
      alert('Input is not alphanumeric'); 
      return false; 
     } 
     else 
     return true;  

    } 
</script> --> 

<script type="text/javascript" src="WEB-INF/script1.js"></script> 


</head> 
<body onLoad="focusFieldOne();"> 


<form:form name="form1" action="login.html" commandName="userDetails" onsubmit="func1()"> 
<table> 
<tr> 
    <td><font face="verdana" size="2px">User</font></td> 
    <td>:</td> 
    <td> 
    <font face="verdana" size="2"> 
    <form:input path="user" /> <form:errors path="user"></form:errors> 
    </font> 
    </td> 
</tr> 


<tr> 
    <td><font face="verdana" size="2px">Password</font></td> 
    <td>:</td> 
    <td> 
    <font face="verdana" size="2"> 
    <form:input path="password" type="password" /> <form:errors path="password"></form:errors> 
    </font> 
    </td> 
</tr> 
<tr> 
    <td> 
    <input type="submit" value="Submit" /> 
    </td> 
</tr> 
</table> 
</form:form> 
</body> 
</html> 

是否有其JavaScript是要添加任何特定的文件夾。

回答

0

WEB-INF文件夾不適用於'公共'文件。首先你必須指定你正在服務的靜態資源(Spring MVC)。從文檔:

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/resources/**").addResourceLocations("/public-resources/"); 
} 

這裏提到的資源文件夾應該在您的Web路徑(不是WEB-INF)中。 有關詳細信息看看文檔http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-config-static-resources