【发布时间】:2014-02-20 13:54:04
【问题描述】:
这是我的jsp文件
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Heelo;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script>
$(function() {
console.log('something');
$.getJSON('test', function(data) {
console.log(data);
});
});
</script>
</body>
</html>
这是我的 servlet 文件
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
Thread.sleep(360000);
} catch (InterruptedException e) {
e.printStackTrace();
}
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
out.write("[]");
}
这是一个发送到 servlet 的请求。但是如果这个 servlet 需要很长时间(例如,6 分钟)来处理,则没有数据打印到控制台。在上面的示例中,我可以看到控制台打印了“某事”,但没有看到“[]”。
但如果我直接对那个 servlet 执行 curl,我可以得到结果。
有什么帮助吗?
【问题讨论】:
-
您为什么希望客户端等待 6 分钟才能得到结果?
-
@MikeBrant 因为我的 servlet 对数据库的查询可能需要很长时间,所以在这里我只是强制它等待 6 分钟以重现问题。