Commit 03595b49 authored by unknown's avatar unknown
Browse files

Initial downloadable link test

parent 4508e43d
Pipeline #170904 passed with stages
in 46 seconds
package ic.doc.web;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
......@@ -30,10 +32,30 @@ public class HTMLResultPage implements Page {
} else {
writer.println("<h1>" + query + "</h1>");
writer.println("<p>" + answer.replace("\n", "<br>") + "</p>");
// Create file
String downloadableFileName = System.nanoTime() + ".txt";
File downloadableFile = new File(downloadableFileName);
if (downloadableFile.createNewFile()) {
// File didn't exist previous
FileWriter downloadableFileWriter = new FileWriter(downloadableFileName);
// Write "answer" to file
downloadableFileWriter.write(answer);
// Reference file in html
writer.println("<p>" +
String.format("<a href=\"/%s\" download>", downloadableFileName) +
"Download file</a>" +
"</p>");
downloadableFileWriter.close();
} else {
// File already exists
}
}
writer.println("<p><a href=\"/\">Back to Search Page</a></p>");
// Footer
writer.println("</body>");
writer.println("</html>");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment