Html 在没有服务器端脚本的情况下设置 Access-Control-Allow-Origin

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26417734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:53:31  来源:igfitidea点击:

Set Access-Control-Allow-Origin without server side scripting

htmltomcatcors

提问by Mishax

I am trying to set the HTTP header "Access-Control-Allow-Origin" but all of the examples that I find involve servlets or PHP or assume that there is server-side scripting available. Is it possible to set this in a plain old HTML file? I have tried this but I cannot verify that it is working:

我正在尝试设置 HTTP 标头“Access-Control-Allow-Origin”,但我发现的所有示例都涉及 servlet 或 PHP,或者假设有可用的服务器端脚本。是否可以在普通的旧 HTML 文件中设置它?我试过这个,但我无法验证它是否有效:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html>
<head>
    <meta http-equiv="Access-Control-Allow-Origin" content="*"/>
...

采纳答案by Christopher Schultz

Try using url-rewrite. You will have to configure the Filter in your web application, but you won't have to write any Java code to do it.

尝试使用url-rewrite。您必须在 Web 应用程序中配置过滤器,但不必编写任何 Java 代码来执行此操作。