java 远程 写文件_java – 如何使用远程文件?

我有一个专门用于静态内容的服务器,所以我不想使用资源目录来存储

javascript文件,但我不想停止使用< h:outputScript />标签.

如何使该标记生成指向文件所在的静态服务器的链接,而不是RES_NOT_FOUND.我甚至不需要JSF检查文件是否存在…

我试过了:< h:outputScript name =“#{requestBean.staticURL} /javascript.js”/>

要生成:< script type =“text / javascript”src =“http://static.server.com/javascript.js”>< / script>

但它会生成:< script type =“text / javascript”src =“RES_NOT_FOUND”>< / script>

我能做什么?

解:

丹尼尔给我一个很好的解决方案!

我已经下载了Omnifaces的源代码并将org.omnifaces.resourcehandler.CDNResourceHandle.createResource(String resourceName,String libraryName)方法修改为:

public Resource createResource(String resourceName,String libraryName) {

final Resource resource = wrapped.createResource(resourceName,libraryName);

if (cdnResources == null) {

return resource;

}

String resourceId = ((libraryName != null) ? libraryName + ":" : "") + resourceName;

String path = cdnResources.get(resourceId);

if(path == null){

if(libraryName != null){

resourceId = libraryName + ":%";

path = cdnResources.get(resourceId);

if(path == null){

return resource;

}

path += "/"+resourceName;

}

else return resource;

}

final String requestPath = path;

return new ResourceWrapper() {

@Override

public String getRequestPath() {

return requestPath;

}

@Override

public Resource getWrapped() {

return resource;

}

};

}

通过此更改,我可以将其添加到我的web.xml文件中

org.omnifaces.CDN_RESOURCE_HANDLER_URLS

somelib2:%=http://cdn.example.com/somelib2,js/script1.js=http://cdn.example.com/js/script1.js,somelib:js/script2.js=http://cdn.example.com/somelib/js/script2.js,otherlib:style.css=http://cdn.example.com/otherlib/style.css,images/logo.png=http://cdn.example.com/logo.png

请注意somelib2:%= http://cdn.example.com/somelib2,这会将somelib2库中的任何资源指向http://cdn.example.com/somelib2中的相对路径,例如:

< h:outputScript name =“js / myjs.js”library =“somelib2”/>

将输出:

< script type =“text / javascript”src =“http://cdn.example.com/somelib2/js/myjs.js”>< / script>

这适用于< h:outputScript />< h:outputStylesheet />< h:graphicImage />,任何使用资源的东西;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值