我的页面a.html是在apache服务器上面的,但是文件是在tomcat服务器上的,我访问的连接就是http://127.0.0.1/a.html?file=http://127.0.0.1:8080/bb.pdf,访问时报错:Unexpected server response (0) while retrieving PDF,请问该如何解决,非常感谢!
1.在项目中添加两个jar包 http://pan.baidu.com/s/1mi58vhe
2.在web.xml中添加代码:
<!--CORSFiltermappingcrossdomainfiltersetting--><filter><filter-name>CORS</filter-name><filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class><init-param><param-name>cors.allowGenericHttpRequests</param-name><param-value>true</param-value></init-param><init-param><param-name>cors.allowOrigin</param-name><param-value>*</param-value></init-param><init-param><param-name>cors.allowSubdomains</param-name><param-value>false</param-value></init-param><init-param><param-name>cors.supportedMethods</param-name><param-value>GET,HEAD,POST,DELETE,OPTIONS</param-value></init-param><init-param><param-name>cors.supportedHeaders</param-name><param-value>content-type,authorization</param-value></init-param><init-param><param-name>cors.supportsCredentials</param-name><param-value>true</param-value></init-param><init-param><param-name>cors.maxAge</param-name><param-value>3600</param-value></init-param></filter><filter-mapping><!--CORSFiltermapping--><filter-name>CORS</filter-name><url-pattern>*</url-pattern></filter-mapping>1.在项目中添加两个jar包 http://pan.baidu.com/s/1mi58vhe
2.在web.xml中添加代码:
<!--CORSFiltermappingcrossdomainfiltersetting--><filter><filter-name>CORS</filter-name><filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class><init-param><param-name>cors.allowGenericHttpRequests</param-name><param-value>true</param-value></init-param><init-param><param-name>cors.allowOrigin</param-name><param-value>*</param-value></init-param><init-param><param-name>cors.allowSubdomains</param-name><param-value>false</param-value></init-param><init-param><param-name>cors.supportedMethods</param-name><param-value>GET,HEAD,POST,DELETE,OPTIONS</param-value></init-param><init-param><param-name>cors.supportedHeaders</param-name><param-value>content-type,authorization</param-value></init-param><init-param><param-name>cors.supportsCredentials</param-name><param-value>true</param-value></init-param><init-param><param-name>cors.maxAge</param-name><param-value>3600</param-value></init-param></filter><filter-mapping><!--CORSFiltermapping--><filter-name>CORS</filter-name><url-pattern>*</url-pattern></filter-mapping>测试无效
fileName="
http://114.215.221.123/ueditor/jsp/upload/file/20170413/1492017493544030070.pdf";
try{
//http://114.215.221.123/ueditor/jsp/upload/file/20170413/1492017493544030070.pdf
//纯下载方式
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition","attachment;filename="+fileName.substring(fileName.lastIndexOf("/"+1),fileName.length()));
URLurl=newURL(fileName);
URLConnectionconn=url.openConnection();
//
byte[]b=readInputStream(conn.getInputStream());
response.getOutputStream().write(b);
response.getOutputStream().flush();
response.getOutputStream().close();
}catch(Exceptione){
e.printStackTrace();
}
写个SERVLET处理下,
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。