0

This is my jsp file

<%@ 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>

And this is my servlet file

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("[]");
}

This is a request sent to a servlet. But if this servlet takes a long time (for example, 6 minutes) to process, there is no data printed to console. In the example above, I can see 'something' printed to console, but no '[]'.

But if I do a curl to that servlet directly, I can get the result back.

Any help?

Cacheing
  • 3,431
  • 20
  • 46
  • 65
  • Why would you expect the client to wait 6 minutes for a result? – Mike Brant Jan 29 '14 at 01:17
  • @MikeBrant Because my servlet has a query to database which may take a very long time, so here I just force it to wait for 6 minutes to reproduce the problem. – Cacheing Jan 29 '14 at 18:07

2 Answers2

0

Since getJSON runs on the client and curl on the server, this could be network related issue. Could you use fiddler/chrome webdeveloper tools to see what is taking time. It could be simple things like name resolution, or webserver configurations.

George Philip
  • 704
  • 6
  • 21
0

It could be time out. See the how to handle time out in the following dicussion.

jQuery getJSON with timeout

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback,
  timeout: 360000
});
Community
  • 1
  • 1
George Philip
  • 704
  • 6
  • 21