Java 在SpringMVC视图中使用AJAX将http.status设置为404

Java 在SpringMVC视图中使用AJAX将http.status设置为404,java,ajax,spring-mvc,Java,Ajax,Spring Mvc,我想使用Javascript在JSP视图中使用AJAX。以下是我的JSP代码signup.JSP: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <!DOCTYPE

我想使用Javascript在JSP视图中使用AJAX。以下是我的JSP代码signup.JSP:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org    /TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<script type="text/javascript">
var http;
function someAjax(){
    alert("ITS still WORKING");

    if(window.XMLHttpRequest){
        http = new XMLHttpRequest();
    }
    **http.open("GET", "AjaxSameUser.jsp", true);**    
    alert("After connection");
    http.onreadystatechange=handleResponse;
    http.send(null);
}

function handleResponse(){
    alert("readyState :" + http.readyState+"   status : "+http.status);
    if(http.readyState==4 && http.status==200){
        alert("State as expected");
        document.getElementById("usernameExists").innerHTML = http.responseText;
    }   
}
</script>
</head>
<body>
<form:form commandName="user" method="POST">
    <table>
        <tr>    
            <td> Username : </td>
            <td> <form:input path="name" id="username" onchange="someAjax()" />  </td>   
              <td> <div id="usernameExists"> Something already </div></td>
        </tr>
            </table>
</form:form>
</body>
</html>

在此处插入标题
var-http;
函数someAjax(){
警报(“其仍在工作”);
if(window.XMLHttpRequest){
http=newXMLHttpRequest();
}
**http.open(“GET”,“AjaxSameUser.jsp”,true);**
警报(“连接后”);
http.onreadystatechange=handleResponse;
http.send(空);
}
函数handleResponse(){
警报(“readyState:+http.readyState+”状态:+http.status);
if(http.readyState==4&&http.status==200){
警报(“按预期状态”);
document.getElementById(“用户名存在”).innerHTML=http.responseText;
}   
}
用户名:
已经有些事了
jsp有一些硬编码数据,它与signup.jsp位于同一文件夹中

我已经检查了http.readyState和http.status。readyState变为4,但状态仍为404

我知道,每个视图请求都必须通过SpringMVC中的控制器。但在这里,为什么我不能在没有Spring干预的情况下直接从Javascript调用JSP页面呢

或者更确切地说,如何在SpringMVC中使用AJAX?我尝试了链接,但它说使用瓷砖,我不熟悉它,因为我是新春


谁能提出一些好办法。

我想这是URL的问题。尝试直接从浏览器访问url(使用类似firebug的插件获取ajax url)。如果问题出在url上,请更正


http.open(“GET”,“AjaxSameUser.jsp”,true)

您的AjaxSamUser.jsp在哪里?它在WEB-INF中吗?@ThinkStiple:不。它和signup.jsp在同一个文件夹中。两者都在/WEB-INF/AllJsp/文件夹中。