簡體   English   中英

修復在Eclipse上的插件開發中缺少CORS標頭Access-Control-Allow-Origin

[英]Fix CORS header Access-Control-Allow-Origin missing on plugin development on eclipse


-我嘗試使用eclipse插件開發和jax-rs來制作模塊化應用程序。
-我想訪問碼頭服務器創建的事件源並及時轉換每個事件。
-當我嘗試訪問事件時,我在運行我的客戶端html 5頁的firefox中收到此錯誤:跨域請求被阻止:同源策略禁止在http:// localhost:9050 / services / events讀取遠程資源。 (原因:CORS標頭“ Access-Control-Allow-Origin”缺失)。
-我知道我必須配置服務器,但是我沒有.htaccess,也沒有web-inf目錄。
-是否有使用eclipse在vm參數中聲明此文件的? -還有其他方法嗎?
-我沒有WEB-INF目錄,也不知道此插件開發方法是否支持該目錄。
-我沒有主要功能,我只有捆綁包(激活劑等),也沒有主要功能。
-我也有manifest.mf文件

我們將接受任何幫助。

嘗試實現一個響應過濾器,該過濾器會將所需的標頭添加到響應中。

@Provider
public class CORSFilter implements ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
        // the wildcard char `*` will allow any origin
        responseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
        // add anything and everything you need
        responseContext.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type");
        responseContext.getHeaders().add("Access-Control-Allow-Credentials", "true");
        responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
        // etc
    }
}

不要忘記注冊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM