java - Spring MVC not resolving image path stored outside webroot -


i uploading images , videos , creating respective tags video , audio display on view page somehow image , video path not getting resolved.

here controller.

@requestmapping(value = "/contentupload", headers = "content-type=multipart/*", method = requestmethod.post) public @responsebody string uploadimage(@requestparam("filedata") multipartfile multipartfile, httpservletrequest request ) {     string jsonresponse = null;     boolean isimage = false;     boolean isvideo = false;     try     {         string path = request.getservletcontext().getrealpath("/");         file directory = null;         if (multipartfile.getcontenttype().contains("image"))         {             directory = new file(path + "/uploads/images/");             isimage = true;         }         else         {             directory = new file(path + "/uploads/videos/");             isvideo = true;         }          byte[] bytes = null;         file file = null;         bytes = multipartfile.getbytes();          if (!directory.exists()) directory.mkdirs();          file = new file(directory.getabsolutepath() + system.getproperty("file.separator") + multipartfile.getoriginalfilename());         bufferedoutputstream stream = new bufferedoutputstream(new fileoutputstream(file));         stream.write(bytes);         stream.close();          if (isimage)             jsonresponse = "<br /><img src=\"" + file.getabsolutepath() + "\" />";         else if (isvideo)             jsonresponse = "<video>" + "<source src=\"" + file.getabsolutepath() + "\" type=\"" + multipartfile.getcontenttype() + "\">" + "</video>";     }     catch (exception e)     {     }            return jsonresponse; }     

i have tried resources settings in dispatcher.

<mvc:resources mapping="/uploads/**" location="/#{servletcontext.contextpath}/uploads/" /> 

uploaded image path.

/home/govi/demo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/projectimg/uploads/images/batman.jpg 

please suggest me changes required.

use below code line, may helps you.

<mvc:resources mapping="/uploads/**"  location="/web-inf/projectimg/uploads/" /> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -