【发布时间】:2018-12-02 15:27:34
【问题描述】:
我是开发网站的新手。 我知道我必须在 web.xml 文件中映射 servlet。 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_3_0.xsd" version="3.0">
<display-name>TestApp</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>
<servlet>
<servlet-name>Serve</servlet-name>
<servlet-class>Serve</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Serve</servlet-name>
<url-pattern>/TestApp</url-pattern>
</servlet-mapping>
</web-app>
但是当我调用 jquery $.ajax() 函数时,我得到了这个错误。
XML 解析错误:语法错误 地点:http://localhost:8080/TestApp/Serve 第 1 行第 1 列:
AJAX 调用是
$.ajax({
url: "Serve",
type: "POST",
success: function(out){
alert(out);
},
error: function(){
alert("No");
}
});
问题是 servlet 仍然运行良好。警报(出)按预期工作。请解释浏览器显示错误的原因并告诉我解决方案。
如果这是一个重复的问题,请提供原始问题的链接。
【问题讨论】:
-
可能是您在
file:///中运行您的应用程序,因为这是可能发生的ajax 请求。如果你已经安装了nodejs,你可以安装一个服务器并查看控制台日志
标签: javascript jquery ajax xml servlets