Forums Register Login

Display ArrayList with line breaks on Default Browser page

+Pie Number of slices to send: Send
I would like to know if there is a quick and easy way to display the results of an Array List of Strings, Formatted with line breaks, to the default web browser page that the URI is called from.

I'm currently using Spring Rest Controller and even though I could go down the route of building another jsp page, I just want to simply print to the default browser page. Currently, it displays with nothing more than just returning the list, but it is hard to decipher because there is no formatting.

I would like to see each line in the array list printed on a new line on the browser page. Nothing fancy, just line breaks after each element.

Example:

Id 10
No Name found for id 10
-----------------------------------------------------------------

Id 15
No Name found for id 15
-----------------------------------------------------------------

Id 13
Name: Some Name
-----------------------------------------------------------------

Here is my code right now, like I said nothing fancy:


Here is the current output:
["Id 10","No Program found for given channel 10", "-----------------------------------------------------------------", "Id 15","No Program found for given channel 15", "-----------------------------------------------------------------","Id 13","Name: Some Name", "-----------------------------------------------------------------"]
+Pie Number of slices to send: Send
Separation of concerns says you should handle the formatting separately from the basic business computation. That suggests using a JSP, and either 1) having an include statement in the JSP that's surrounded by <code> </code> to maintain the line breaks, ir 2) get the data in a raw form, bypassing the REST service entirely, and using <c:foreach and EL to do the presentation. The second is going to be more flexible and maintainable.
>
+Pie Number of slices to send: Send
Appreciate the reply Simon, but that's not what I'm looking for. Whether it follows proper design pattern is not what I am concerned about, this is internal to my own network so I just want to see if this can be done. It displays to the page anyway, I would think there has to be a way to have it formatted or at least display the way it is stored by default.

+Pie Number of slices to send: Send
The API and related tools are designed for professional use. What you want, as I interpret your statement, is a "quick and dirty hack". Nothing wrong with that, but it's not particularly likely that something exists in the API to support it ;)

So, my guess is that the solution of least resistance, assuming you need a web-page, would be to create a JSP that includes the REST output, but puts the <code> tags around it.

If you don't actually need a web page, then use either a REST testing client like POSTman in your browser, or a command line tool like curl.
Quick! Before anybody notices! Cover it up with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 690 times.
Similar Threads
setting a default value for a drop-down
Java Applet Access Problem
How should JPQL query look like for described scenario?
java
Struts 2 and auto population of HTML tables
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:39:33.