How do I upload a file from a Java servlet to a location on a web server within Tomcat/webapps

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-03-09T03:49:05Z Indexed on 2010/03/09 3:51 UTC
Read the original article Hit count: 264

How do I upload a file from a Java servlet to a location on a web server within Tomcat/webapps.

I am using Commons upload. I have a location such as myserver:8080/myapp/mylocation where I want to put the files that are uploaded.

I tried using getServletContext().getRealPath("/"); to find where I am and then appended that with mylocation but I get a nullpointer exception.

I know I sound vague, it's because I am confused about the big picture, what are the generals steps I need to perform to make this work. Any code or links to code would be much appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about servlet