Jquery无法向servlet发送错误404发送请求

时间:2016-02-20 08:00:00

标签: java jquery ajax servlets

我正在向servlet发送ajax请求。 Ajax代码:

                 $.ajax({
                        type : "POST",
                        url : "/SignUp",
                        data: dataString,
                        // if received a response from the server
                        success : function(data, textStatus, jqXHR) {
                            console.log("Transfering ");

                        },

                        error : function(jqXHR, textStatus, errorThrown) {
                            alert("Something really bad happened " + textStatus);
                        }
                    });
              }

Servlet路径: 我的servlet现在正在托管。它位于:  的域/的public_html / WEB-INF /类/控制器/ AUTH /注册

我的Web.xml条目

             <servlet>
               <description></description>
               <display-name>SignUp</display-name>
               <servlet-name>SignUp</servlet-name>
               <servlet-class>.controller.auth.SignUp</servlet-class>
            </servlet>

             <servlet-mapping>
                 <servlet-name>SignUp</servlet-name>
                  <url-pattern>/SignUp</url-pattern>
             </servlet-mapping>

On Every Ajax call i am getting error 404 not found.

我的Web.XML文件是

               <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                      xmlns="http://java.sun.com/xml/ns/javaee"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
       <display-name>CarPool</display-name>
   <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
         <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
  <servlet>
     <description></description>
    <display-name>Login</display-name>
    <servlet-name>Login</servlet-name>
   <servlet-class>controller.auth.Login</servlet-class>
 </servlet>
  <servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>/Login</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <display-name>SignUp</display-name>
    <servlet-name>SignUp</servlet-name>
    <servlet-class>controller.auth.SignUp</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>SignUp</servlet-name>
   <url-pattern>/SignUp</url-pattern>
 </servlet-mapping>
 <servlet>
    <description></description>
   <display-name>ResetPassword</display-name>
   <servlet-name>ResetPassword</servlet-name>
     <servlet-class>controller.auth.ResetPassword</servlet-class>
  </servlet>
  <servlet-mapping>
   <servlet-name>ResetPassword</servlet-name>
    <url-pattern>/ResetPassword</url-pattern>
  </servlet-mapping>
  <servlet>

1 个答案:

答案 0 :(得分:0)

尝试更改servlet-class路径:

    <servlet-class>.controller.auth.SignUp</servlet-class>

删除第一个点.

    <servlet-class>controller.auth.SignUp</servlet-class>

这里使用contextPath这样写正确的路径:

 <script>var contextPath = "${pageContext.request.contextPath}";</script>
   url :contextPath + "/SignUp",