Pregunta

i wrote file upload programme in jsp in elipse id using cos.jar described in this link i got desired output.

-> now i want to specify the path folder to store image in server to be dynamic, because if this path is fixed type to particular directory in the server my project won't be portable, how to get rid of this.

path given in servlet is as follows :

MultipartRequest m=new MultipartRequest(request,"E:/workspace/fileUpload/WebContent/uploads/");

want to know if there exists any regular expressions or some alternate method like : ${project_path} and also like to know how to Validate uploads using Java scripts.

¿Fue útil?

Solución

When we deploy any web application on server.There is a path something like

http://<host>:<port>/<contextPath> 

this to access that deployed webapp.

Now you can set some specific folder in that live web directory where you can save image dynamically.Now with this Get Realpath you can get realpath of your webapp and then append your specified folder's path with that realpath you can save your images so that it will be independent from static path.

Suppose as a example:

I have one application ABC and deployed on http://www.xyz.com/ABC/ (Context path of deployed webapp). Now in database or in property file or in code I specified one folder named as profilepics in war file.In my method I will get realpath(context path) and append that folder name so path is like http://www.xyz.com/ABC/profilepics/ which store images uploaded by user.Donlt forget to add security to that folder if content stored in that directory is confidential.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top