如何在ResourceStreamRequestHandler中配置setHeader #configure(..)(迁移问题)

时间:2015-06-10 13:05:20

标签: java wicket wicket-1.5 wicket-6

我正在将wicket 1.4迁移到6到1.5。我遇到了一个无法解决的问题。在wicket 1.4我曾经有过(注意:是的,我确实有detach

public class TempFileResourceRequestTarget extends ResourceStreamRequestTarget implements Serializable {
    @Override
    protected void configure(final RequestCycle requestCycle, final Response response, 
            final IResourceStream resourceStream) {
        super.configure(requestCycle, response, resourceStream);
        ((WebResponse)response).getHttpServletResponse().setHeader("Cache-Control","");
        ((WebResponse)response).getHttpServletResponse().setHeader("Pragma","");
}

在wicket 1.5 / 6中,我将其改为:

public class TempFileResourceRequestTarget extends ResourceStreamRequestHandler implements Serializable {
    @Override
    protected void configure(ResourceStreamResource resource) {
        super.configure(resource);
        ((HttpServletResponse)resource).setHeader("Cache-Control","");
        ((HttpServletResponse)resource).setHeader("Pragma","");
    }
}

我很绝望,并试图找到任何包含setHeader()的东西 - 我相信我在迁移指南中找到了它或类似的东西。无论如何这不起作用。我该如何设置?在renderHead?没有线索。提前谢谢。

1 个答案:

答案 0 :(得分:1)

ResourceStreamResource未实施HttpServletResponse。 您可以使用ResourceStreamResource#setCacheDuration(Duration.NONE)禁用缓存。

它将为您执行以下操作:

 public void disableCaching() {
    this.setDateHeader("Date", Time.now());
    this.setDateHeader("Expires", Time.START_OF_UNIX_TIME);
    this.setHeader("Pragma", "no-cache");
    this.setHeader("Cache-Control", "no-cache, no-store");
 }

这就是你想要的吗?