transferring uninterrupted text data from Java programming to HTML using an HTTP request

I am currently in the process of designing an application where I am executing HTTP POST requests using Angular. These requests are then received by Java code, which processes them and generates logs consisting of approximately 50-60 lines at a rate of one line per second. Instead of waiting for the request to finish before displaying all the logs at once, I would like to showcase them on my HTML page as they are being generated. Is there a way to achieve this continuously?

JAVA CODE

The Java code creates an array of logs with a size of 50-60. It takes about 60-90 seconds to complete the operation, and after converting the logs to JSON format, the array is sent using the following code:

response.getWriter.write(applogs)

JAVASCRIPT CODE

var httpPostData = function (postparameters, postData){

return $http ({           
method  : 'POST',
url     : URL,
params  : postparameters,
headers: headers,
data    : postData
}).success (function (responseData){
     return responseData.data;
})
}

var addAppPromise = httpPostData(restartAppParams, app);
addAppPromise.then(function (logs){
      $scope.logs = logs.data;
})         

HTML Code

<span ng-repeat="log in logs">{{log}}<br></span>

Answer №1

There are a couple of approaches you can take:

  1. (Less aesthetically pleasing but quicker and simpler) Have your service respond immediately without waiting for 'stuff' to be generated, then create a second service that retrieves logs created so far. Implement polling in JavaScript: call the second service at regular intervals to update the view.
  2. Utilize EventSource to receive server-sent events. While websockets are an option, EventSource should suffice since you only require one-way communication from server to client. Keep in mind, however, that this API may necessitate polyfills for IE/Edge and specific server-side handling.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to conceal various components while showcasing just a single element from every individual container

I am looking to only display specific span elements within their parent container (coin) while hiding the rest. The desired output should show only "1" and "first" while the other spans are hidden. <div class="types"> <div class=" ...

How can ThreeJS utilize CSS3Renderer and WebGLRenderer to display two objects in the same scene and achieve overlapping?

JSFiddle : http://jsfiddle.net/ApoG/50y32971/2/ I am working on a project where I am using CSS3Renderer to render an image as a background projected as a cube in the app. However, I also want to incorporate objects rendered using WebGLRenderer in the mid ...

Is it possible to use the ""get" prefix for a function in Spring Boot?

I am facing an issue with my Mcq class that is linked to a MongoRepository. I am trying to retrieve an instance of my Mcq after applying certain changes such as shuffling answers and drawing questions. I have defined a function called "myMcq.getInstance()" ...

Setting up a Webpack configuration to compile modules within the node_modules directory

My webpack and babel configuration is causing some issues. I installed my component repository (es6 module without webpack configuration) as a node_module, but it's not working - I'm getting an 'Unexpected token import' error because Ba ...

jQuery Toggle and Change Image Src Attribute Issue

After researching and modifying a show/hide jQuery code I discovered, everything is functioning correctly except for the HTML img attribute not being replaced when clicked on. The jQuery code I am using: <script> $(document).ready(function() { ...

Ensuring the value of a v-text-field in Vuetify using Cypress

I am currently developing an end-to-end test suite using Cypress for my Vue and Vuetify frontend framework. My goal is to evaluate the value of a read-only v-text-field, which displays a computed property based on user input. The implementation of my v-tex ...

Creating a spherical shape using random particles in three.js

Can anyone assist me in creating a random sphere using particles in three.js? I can create different shapes with particles, but I'm unsure how to generate them randomly. Here's my current code: // point cloud geometry var geometry = new THREE. ...

Implementing SVG in NextJS 13 with custom app directory: A step-by-step guide

Recently, I decided to explore the app directory and unfortunately ran into some issues. One of the main problems I encountered was with image imports. While PNG images imported without any problem, SVG images seemed to break when importing in /app. For i ...

View is unable to trigger the success attribute

Currently, I am delving deep into Backbone JS and facing an issue where the 'success' function in 'EditUser' is not being triggered. I would greatly appreciate it if someone could guide me on what changes I need to make in the code? B ...

Bidirectional Data Binding in AngularJS Directive

My custom directive is defined like this: .directive('test', function () { return { scope: {}, link: function (scope, element, attr) { scope.$parent.$watch(attr.selectedItem, function(newValue, oldValue){ ...

Make sure to wait for the loop to complete before moving on to the next line

I am currently leveraging the capabilities of the GitHub API to fetch a list of repositories. Subsequently, I iterate over each repository and initiate another HTTP request to obtain the most recent commit date. How can I orchestrate the iteration process ...

displaying pictures exclusively from Amazon S3 bucket using JavaScript

Considering my situation, I have a large number of images stored in various folders within an Amazon S3 bucket. My goal is to create a slideshow for unregistered users without relying on databases or risking server performance issues due to high traffic. I ...

Transferring window object between different pages

When you navigate from Page A to Page B, and then to Page C, the connection between all three pages can be utilized for efficient page management. For instance, once Page C is fully loaded, Page A can be automatically closed. To seamlessly transition from ...

Generating an HTTP response to be returned by Mockito

I am currently learning about Mockito testing and I have been working on testing a GET request. After mocking the call, I now need to figure out how to return a HttpResponse<Cars[]>, as these values will be used later in a for loop. Does anyone kno ...

Tips for updating the name of a variable (such as 'data') following the process of destructuring, like with the

If I have 2 SWR hooks in the same function (or some other hook that contains a data variable), export default function Panel() { const { data, error } = useSWR("/api/customer", fetcher); const { data, error } = useSWR("/api/user", fetch ...

Improper comment placement in Rails with AJAX and JQUERY

I am developing a "comment system without page refreshing" using Jquery and Ajax. Within posts/show.html.erb <%= @post.title %> <%= @post.body %> <%= render 'comment %> posts/_comment.html.erb <%= link_to "Add Comment", new_po ...

Resetting the internal state in Material UI React Autocomplete: A step-by-step guide

My objective is to refresh the internal state of Autocomplete, a component in Material-UI. My custom component gets rendered N number of times in each cycle. {branches.map((branch, index) => { return ( <BranchSetting key={ind ...

How can I update the background color of the specified element when the text changes without triggering a postback?

Seeking guidance on JavaScript as I am not very adept in it. We have a webpage where users upload .XLS/.CSV files and review the data before submitting it to our database. Users can edit cells in the uploaded document on our "review" screen before final su ...

TS: Deduce explicit typing through method chaining

After overcoming all obstacles, I am finally ready to unleash the first version of my form validation library. Below is a snippet of the code (simplified for clarity) interface Validation { name: string message: string params?: Record<string, any ...

Adding ng-add & npm link - A guide to mocking the npm registry

I'm currently working on a collection of schematics for @angular/cli and I want to test it locally. Is there a way to test the ng-add CLI feature locally? When I link my project using npm link and run ng add myFeature, @angular/cli attempts to downl ...