简体   繁体   中英

Not allowed to load local resource: JSP

I want to download a simple file by a link in jsp, but this name have a Chinese characters. Here my simple code :

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!doctype html>
<html lang="fr">
  <head>
   <meta charset="utf-8">
   <title>Titre de la page</title>
  </head>
 <body>
     <a href="C:\Files\4.导轨安装板.PDF" target="_blank">My link </a>
 </body>
 </html>

that gives an error in navigator console : Not allowed to load local resource.

Thank you for your help :)

The problem are not the characters is the fact that you are trying to access the local disk. Your code is executing in a browser, and, for security reasons, you cannot access the local disk of the machine on which the page is displayed. Not to mention that, if that would have been allowed, it will load something different on every machine it runs on :). So, either you use relative path in your HREF, or full URLs. Remember, when you specify a link it goes to the SERVER to get the resource, not from local machine on which the browser is running.

Do not import or load local resource in this format:

src="file://home/web-server/foo/bar.jpg"

Because modern browsers not allowed to load files on server disk.

I suggest that you tell your proxy server to server the dir

foo

as a static file dir which browsers can access via your proxy server. In NodeJS, it will be like (suggest this file in /home/web-server named app.js)

var express = require("express");
var app = express();
app.use(express.static(path.join(__dirname, 'foo')));

Now, in your html code, you can call

<a href="4.导轨安装板.PDF" target="_blank">My link </a>

Then, you will see browser access your file by

http://yourdomain.com/4.导轨安装板.PDF

which will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM