我试图通过jquery ajax调用servlet类但是我失败了,并且得到了这个错误。我该怎么做才能解决它?
POST http//localhost:8080/AkiDar/CpanelServlet 404 (Not Found) jquery-1.8.2.js:8416
send jquery-1.8.2.js:8416
jQuery.extend.ajax jquery-1.8.2.js:7968
sendToServlet
onclick
这是jQuery Ajax
var mainDesID=document.staticForm.mainDesID.value;
var firstName=document.staticForm.firstName.value;
var lastName=document.staticForm.lastName.value;
var address=document.staticForm.address.value;
var xpoint=document.staticForm.xpoint.value;
var ypoint=document.staticForm.ypoint.value;
var xstreet=document.staticForm.xstreet.value;
var ystreet=document.staticForm.ystreet.value;
var phoneNumber=document.staticForm.phoneNumber.value;
var email=document.staticForm.email.value;
var url=document.staticForm.url.value;
var description=document.staticForm.description.value;
var details=document.staticForm.details.value;
var type=document.staticForm.type.value;
var json= {
'mainDesID':mainDesID ,
'firstName':firstName,
'lastName':lastName,
'xpoint':xpoint,
'ypoint':ypoint,
'xstreet':xstreet,
'ystreet':ystreet,
'address':address,
'phoneNumber':phoneNumber,
'email':email,
'url':url,
'description':description,
'type':type,
'specialize':'dddd',
'details':details
};
console.log(json);
$.ajax({
url:"/AkiDar/CpanelServlet",
type:"POST",
dataType:'json',
success:function(data){
},
data:json
});
和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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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>AkiDar</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>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
答案 0 :(得分:2)
您没有在web.xml文件中声明任何servlet,也没有映射任何URL。显然,你的servlet不可用。
这里是解释如何声明和映射servlet的a tutorial。您需要在web.xml中使用以下内容:
<servlet>
<servlet-name>someServletName</servlet-name>
<servlet-class>fully.qualified.name.of.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>someServletName</servlet-name>
<url-pattern>/CpanelServlet</url-pattern>
</servlet-mapping>