我正在向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>
我的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>
答案 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",