× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to load big file from UI

Ilvin
Dec 20, 2016
<p>1. set <strong>maxPostSize </strong>in Tomact to 0 </p> <p>2. Little example with comments:</p> <pre><span style="color:#cc7832">public class </span>DownloadServlet <span style="color:#cc7832">extends </span>HttpServlet { <span style="color:#bbb529">@Override </span><span style="color:#bbb529"> </span><span style="color:#cc7832">protected void </span><span style="color:#ffc66d">doPost</span>(HttpServletRequest req<span style="color:#cc7832">, </span>HttpServletResponse resp) <span style="color:#cc7832">throws </span>ServletException<span style="color:#cc7832">, </span>IOException { ServletInputStream inputStream = req.getInputStream()<span style="color:#cc7832">; </span><span style="color:#cc7832"> </span><span style="color:#808080">// also you can try req.getReader() and work with reader (Reader is only for human recognizable files). </span><span style="color:#808080"> // but if you need just load file inputStream is enough </span><span style="color:#808080"> </span><span style="color:#cc7832">byte </span>buffer [] = <span style="color:#cc7832">new byte</span>[<span style="color:#6897bb">1026</span>]<span style="color:#cc7832">; </span><span style="color:#cc7832"> while</span>(inputStream.read()&gt;=<span style="color:#6897bb">0</span>){ inputStream.read(buffer)<span style="color:#cc7832">; </span><span style="color:#cc7832"> </span><span style="color:#808080">//Here you need to write data "buffer" to some temporary file if you don't want memory leak </span><span style="color:#808080"> //If you will write everything to some variable it will create problem with memory </span><span style="color:#808080"> </span>} inputStream.close()<span style="color:#cc7832">; </span><span style="color:#cc7832"> </span>} }</pre>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus