0

I have an endpoint: getHtmlContent in my Java code. It returns me a String with actual HTML code e.g.: <pre>Hello world \n Line 2 </pre>

On my web page I have two options: View, and Download.

When the user clicks on Download, I will call getHtmlContent endpoint that will get me actual HTML content as String.

How do I write that response to a file such that the user is actually able to download the content as content.html file?

How do I render the View option?

David Walschots
  • 12,279
  • 5
  • 36
  • 59
nisha kanani
  • 273
  • 1
  • 4
  • 16
  • 2
    [Google search for you](https://www.google.es/search?safe=strict&rlz=1C1GGRV_enES767ES770&ei=T8OvWu-hIaLjsAenlrWYDA&q=content+type+response+Content-Type%3A+application%2Foctet-stream+Content-Disposition%3A+attachment%3B+filename%3D"test.txt"&oq=content+type+response+Content-Type%3A+application%2Foctet-stream+Content-Disposition%3A+attachment%3B+filename%3D"test.txt"&gs_l=psy-ab.3...5787.9356.0.9505.1.1.0.0.0.0.0.0..0.0....0...1c.1.64.psy-ab..1.0.0....0.P3BUgBvLSDE) – Ele Mar 19 '18 at 14:04
  • Check this link to render string as html content https://stackoverflow.com/a/18342738/2079271 – Gowthaman Mar 19 '18 at 14:26
  • This link can be useful https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server – Jonathan Anctil Mar 19 '18 at 15:58
  • I am at a point where I did something like this : download. getContent is a function that pulls the data from my api end point. However this download attribute in tag downloads a file even before I get response from my api which is stored in "htmlContent" – nisha kanani Mar 19 '18 at 19:27

0 Answers0