After reviewing my previous posts addressing this question, I am still struggling to figure out how to implement it in my program. Here is what I need:
From a JSP page, I make an AJAX call to a servlet like this:
$(document).on('click' , '#gettopevents' , function(event) {
var field = $("input[name = 'field']").val();
if(field === "")
{
$('#responsemsg').html("Please enter a field");
}
else
{
var dataform = { 'field' : field };
$.ajax({
url : 'GetAllLogs',
type : 'POST' ,
data : dataform ,
success : function(response) {
$('#displaylist').load('listgeneration.jsp');
},
error : function(){
alert("Error occurred");
}
});
}
event.preventDefault();
});
The servlet execution is a lengthy process and requires some time. Therefore, I want to display a progress bar to indicate the status of the servlet's execution. Specifically, I would like it to work like this:
@WebServlet("/GetAllLogs")
public class GetAllLogs extends HttpServlet
{
public void doGet(HttpServletRequest request , HttpServletResponse response) throws ServletException , IOException
{
PrintWriter obj = response.getWriter();
obj.print(10);
// Set progress bar value to 10%
....
....
obj.print(40);
// Change progress bar value to 40%
.....
.....
obj.print(100);
//Change progress bar value to 100%
}
}
I essentially need to update the progress bar for every print value in the servlet. Is this approach feasible, and if so, how can I achieve it? Thank you in advance.