如何在 ResourceStreamRequestHandler#configure(..) 中设置标头(迁移问题)
How to setHeader in ResourceStreamRequestHandler#configure(..) (migration issue)
我正在通过 1.5 将 wicket 1.4 迁移到 6。我遇到无法解决的问题。在 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() 的东西——我相信我在迁移指南或类似的东西中找到了它。无论如何,这是行不通的。我该如何设置?在渲染头?没有线索。提前致谢。
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");
}
这就是你想要的吗?
我正在通过 1.5 将 wicket 1.4 迁移到 6。我遇到无法解决的问题。在 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() 的东西——我相信我在迁移指南或类似的东西中找到了它。无论如何,这是行不通的。我该如何设置?在渲染头?没有线索。提前致谢。
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");
}
这就是你想要的吗?