Im doing a small webb application in JSP which needs to have a file upload function.
Problem is that I cant find out how to get the relative path to my webcontents folder. I need a dynamic way to get there so I can save the files in a folder relative to that path.
So far I have tried:
String requestURI = request.getRequestURI();
String contextPath = request.getContextPath();
String realPath = request.getRealPath();
String servletPath = request.getServletPath();
None of them gives the actual WebContents path. I guess there is one method I have overlooked but cant find out which.
use
request.getServletContext().getRealPath("/");
servletContext.getRealPath()Don't do that! First, getRealPath works only if your webapp is expanded and second if you redeploy your app, the entire upload is wiped out.
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