pdf.js 跨域问题

发布于 2021-12-02 01:34:32 字数 189 浏览 848 评论 5

我的页面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,请问该如何解决,非常感谢!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浅沫记忆 2021-12-05 11:40:34

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()));
     URL url = new URL(fileName);
     URLConnection conn = url.openConnection();
  //    
      byte[] b= readInputStream(conn.getInputStream());
     response.getOutputStream().write(b);
     response.getOutputStream().flush();
     response.getOutputStream().close();
    } catch (Exception e) {
     e.printStackTrace();
    }

写个SERVLET处理下,

无声静候 2021-12-05 05:41:33

测试无效

狠疯拽 2021-12-05 04:33:42

测试无效

泛滥成性 2021-12-04 09:50:09

引用来自“smileqingyuan”的评论

1.在项目中添加两个jar包 http://pan.baidu.com/s/1mi58vhe

2.在web.xml中添加代码:

<!-- CORS Filter mapping cross domain filter setting -->
  <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>
		<!-- CORS Filter mapping -->
		<filter-name>CORS</filter-name>
		<url-pattern>*</url-pattern>
	</filter-mapping>

柳絮泡泡 2021-12-02 16:30:43

1.在项目中添加两个jar包 http://pan.baidu.com/s/1mi58vhe

2.在web.xml中添加代码:

<!-- CORS Filter mapping cross domain filter setting -->
  <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>
		<!-- CORS Filter mapping -->
		<filter-name>CORS</filter-name>
		<url-pattern>*</url-pattern>
	</filter-mapping>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文