• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display ArrayList with line breaks on Default Browser page

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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", "-----------------------------------------------------------------"]
 
Author
Posts: 285
12
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
>
 
Raistlen Majere
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Simon Roberts
Author
Posts: 285
12
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic