After hours of searching, I still couldn't find a simple solution to my problem. I need to make something easy.
I have a Java class that contains a map of "Service" objects along with an integer variable called "lastCustomer". When this value changes, how can I ensure that the data displayed on my page stays updated without needing a refresh?
I know I'm supposed to use AJAX and JavaScript, but I'm not sure where to begin.
EDIT:
I think I may have made some progress, but now I'm stuck on the parsing aspect. Currently, I have a servlet set up to retrieve the data and display it at "/display/something". How can I access this data using jQuery?
In essence, I have a list of dynamic objects that I need to display and update their values.
Also, the JSON string provided by the servlet does not automatically update itself; it requires a manual refresh. I believe I'm overlooking some fundamental concept here.
Here is some code:
@WebServlet("/JsonServices")
public class JsonServices extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
Gson gson = new Gson();
String json = gson.toJson(myClass.services());
response.setContentType("application/json");
response.getWriter().println(json);
}
}