2
I need to make a web application that the user uploads PDF files and can download them later. The upload part is done, save the files to a folder on my PC /home/william/web
. To save the files on my PC, I edited the file server.xml
Apache Tomcat adding:
<Context docBase="/home/william/web" path="/teste"/>
This is the code snippet from index.html
where the user sends the files:
<p>Mande seu arquivo PDF aqui:</p>
<form action="./UploadServlet" method="post" enctype="multipart/form-data">
<input name="arquivo" type="file">
<input name="Enviar" type="submit">
</form>
The form with the file goes to Uploadservlet for the doPost method:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Part p = request.getPart("arquivo");
p.write("/home/william/web/webbla" + p.getSubmittedFileName());
}
Now I would need to make the downloads available to the user. I made a page upload.html
, There I tried to put several paths trying to access the PDF, but I can’t. My project is inside the Netbeansprojects folder, which in turn is on /home/william
. The PDF files are in /home/william/web
.
The question seems good to me and I am particularly interested because I’ve run into this problem (or something very similar) in the past and I couldn’t solve it. Unfortunately, your question is with 3 votes of closure as "is not clear enough". I really would not like your question to be closed, because it seems to me to be a great question. But anyway, let’s see if we can clarify better: Your text does not make very explicit what you want. Your problem is the upload that isn’t working? Or it works and your only problem is that you can’t download?
– Victor Stafusa
I already understood and I found a solution, but not to post here: http://www.guj.com.br/java/134723-howto return um-download-por-um-servlet
– Shura16