I have a web project. After executing the project it will generate a text file that will contain certain result. And in the final jsp page just contains success report. But I want to show the content of the text file in to that jsp page. What i need to do to achive this?
Thanks. koushik
If the file is saved in public webcontent, then use JSTL <c:import>
to display it.
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...
<pre><c:import url="file.txt" /></pre>
The <pre>
tag is necessary so that newlines are been preserved in HTML output. Alternatives are adding CSS white-space: pre;
to the containing element, or replacing \n
with <br/>
.
If the file is not saved in public webcontent, then create a servlet which gets an InputStream
of it by FileInputStream
and writes it to the OutputStream
of the HttpServletResponse
so that you can finally use <c:import>
for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With