我正在尝试演示简单的Ajax/Servlet request.For --我已经在eclipse中创建了一个新的动态web项目,并添加了一个简单的Servlet来接受请求并将同样的请求返回到UI中。我已经在web.xml中包含了Servlet的详细信息。我使用Tomcat作为我的服务器。目前还没有构建脚本(我觉得这一点不需要)
Servlet代码:
response.setContentType("text/html");
PrintWriter out =response.getWriter();
String txt = request.getQueryString();
out.println(txt);“联合来文法典”:
$(function(){
$.get('/jirarequest','OK',function(op){
$('#maindiv').appendTo(op);
});
});Html代码:
<?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"
id="WebApp_ID" version="3.0">
<display-name>Jira-Synchronization</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>JiraSyncServlet</servlet-name>
<servlet-class>src.JiraSyncServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>JiraSyncServlet</servlet-name>
<url-pattern>/jirarequest/*</url-pattern>
</servlet-mapping>
我的项目结构:

我的HTML:

我在火虫里说错了
"NetworkError: 404 Not Found - http://localhost:8080/jirarequest?OK"我在浏览器中使用的URL是http://localhost:8080/Jira-Synchronization/index.html。我已经检查过所有的错误了。我通过设置断点进行了调试,但调试器从未击中我的Servelt。我不知道是怎么回事?URL是错误的,接线是错误的,还是它设置某些东西的方式丢失了?
发布于 2013-08-06 17:45:10
一些信息:
我们所知道的事物的集合需要改变:
$.get('/jirarequest/whatever','OK',function(op){和
<servlet>
<servlet-name>JiraSyncServlet</servlet-name>
<servlet-class>JiraSyncServlet</servlet-class>
</servlet>此外,您还可以通过键入这个URL在浏览器中进行测试,这个URL应该返回OK:
http://localhost:8080/Jira-Synchronization/jirarequest/whatever?OKhttps://stackoverflow.com/questions/18086247
复制相似问题