开发者

GWT: response.setHeader - howto?

Hi i have a开发者_JS百科 Google Web Toolkit project. I would like to use

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");

But I have no idea hot to set the header in GWT. I have this "starter" application:

public class Starter extends HttpServlet {

    @Override
    public void init() throws ServletException {
      //do something    
    }
}

But how can I get access to "response"? I need a "HttpServletResponse". But how and where should I put it? I saw this request: Client side caching in GWT , its something like mine, but its not helping.

Thank you


I wrote an answer here, which explains how to set headers using a filter (my example code should work in all servlet containers, like Tomcat, Jetty, ...)

This can be applied both to static files (if you serve them from your servlet container), as well as to your Servlets (just make sure, that the Filter applies to the same path as your Servlet - then your Filter will "wrap" the Servlet. This is more convenient than putting the header code directly in your Servlets, which is also possible in your doGet() or doPost() methods.)

Another option would be to put a reverse proxy server in front of the web server, and let it add the caching headers based on the request URI (or maybe for all POST requests, etc.)

With GWT, it's very important to make sure that the correct caching headers are set for the different resources - see my question here. In case of doubt, always choose not to cache, and then introduce caching step-by-step!


Are you using GWT AJAX (AsyncCallBack etc) ?

if you are just embedding your GWT module inside an existing JSP, and invoking server side methods through AJAX, then you don't have access to the response object. The GWT framework takes care of sending a request as an XmlHttpRequest and getting it back and redrawing the browser DOM. You do not have fine grained control over the response.


One option to look at would be to set up a filter so your requests go through it. There you may be able to alter response headers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜