Skip to content
Advertisement

How would I give immediate feedback in a JSP?

I have a JSP form, that (when the user clicks the “submit” button) instantiates a Java class, and calls a method on it. This method then submits a request (in a proprietary format) to a server running on an entirely different box. That back-end server then either sends the submitting user an email, and returns “SUCCESS” to the Java method, or it returns an error message.

Once the Java method returns from calling the program on the other box, it passes the result to the JSP, which either tells the user to expect an email, or displays the error message it got.

The problem is that this takes time to happen. And as the back-end server has evolved, and become more complex (it now has to call a web service running on a cloud server), that response time has gotten longer.

And now we have users who, because there’s no immediate feedback, are either re-clicking the submit button, or refreshing.

Is there a way I can give the user some kind of immediate feedback, as soon as the JSP begins to process the “submit,” that will be sent before the whole chain of instantiation, method call, remote system call, and so forth begins?

Answer

I found something on my own that will be good enough: I can do an “out.println()” followed by an “out.flush,” and that will give immediate feedback. A quick-and-dirty test proves it out. And the fact that I wasn’t already aware of it shows just how little I know about JSP (although I will note that it never came up in the first JSP tutorial I found, and it wasn’t until I looked at other tutorials that I was even aware of its existence).

But I’d welcome a better solution.

Just as I always welcome constructive criticism.

Advertisement