Java 下载和转发xls

Java 下载和转发xls,java,spring,xls,Java,Spring,Xls,我做了一项服务,应该下载一个excel文件并传递给用户。 下载方法: private void fetchCompanyInfo(int id) throws IOException{ URL url = new URL("https://xxxxxxxxxx"); URLConnection con = url.openConnection(); String query = "ID="+java.net.URLEncoder.encode(String.value

我做了一项服务,应该下载一个excel文件并传递给用户。 下载方法:

private void fetchCompanyInfo(int id) throws IOException{
    URL url = new URL("https://xxxxxxxxxx");


    URLConnection con = url.openConnection();
    String query = "ID="+java.net.URLEncoder.encode(String.valueOf(id),"UTF-8"); 

    String cookie = "";
    for (String tmp: this.cookies)
    {
        System.out.println(tmp);
        cookie += tmp.split(";")[0] + ";";
        System.out.println(cookie);
    }

    con.setRequestProperty(COOKIE, cookie);
    System.out.println("this is the cookie: " + cookie);
    con.setRequestProperty("Content-length", String.valueOf(query.length())); 
    con.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
    con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)"); 
    con.setDoOutput(true); 
    con.setDoInput(true); 


    OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
    out.write(query);
    out.close();


    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String receive = "";
    do {
        String line = in.readLine();
        if (line == null)
            break;
        receive += line;
    } while (true);
    in.close();

    excel = receive;
    System.out.println(receive);

}
这是控制器:

@RequestMapping(value="/test", produces="application/x-msexcel")
public CompanyInfo test() throws IOException {        
    return new CompanyInfo();
}
来自im调用的站点的响应返回 内容处置:附件;filename=Company123.xls; 内容类型:应用程序/x-msexcel
所以我只想转发那个附件

问题是什么?我从我的服务中获取的一个站点获取附件。我想从我的服务下载它。