Spring Java get webapp file path

Source: Internet
Author: User

Spring Java get webapp file path

    @RequestMapping ("/act/worldcup_schedule_time/imgdownload")    @ResponseBody    public  String Scheduledownload (httpservletrequest request, HttpServletResponse response, HttpSession session) {        Response.setcharacterencoding ("UTF-8");         = "Worldcup.jpg";         NULL ;         Try {            request.setcharacterencoding ("UTF-8");

String osname = System.getproperties (). GetProperty ("Os.name");
String sp = (osname.equals ("window")? "\\" : "/");

//get the path to the file//String url = session.getservletcontext (). Getrealpath ("/") + "Resources\\images\\act\\worldcup_merge\\world Cup720.png ";String URL = session.getservletcontext (). Getrealpath ("/") + "Resources/images/act/worldcup_merge/worldcup720.png";            System.out.println (URL); File File=NewFile (URL); Input=fileutils.openinputstream (file); byte[] data =Ioutils.tobytearray (input); //System.out.println ("FileName:" +downloadname);Response.reset (); //set the header information for the response (Chinese problem resolution)Response.setheader ("Content-disposition", "attachment;filename=" + urlencoder.encode (downloadname, "UTF-8")); Response.AddHeader ("Content-length", "" "+data.length); Response.setcontenttype ("Image/png; Charset=utf-8 ");        Ioutils.write (data, Response.getoutputstream ()); } Catch(Exception e) {logger.error ("Error downloading Picture"); if(Input! =NULL) {ioutils.closequietly (input); }        }        return NULL; }

Spring Java get webapp file path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.