1

How to configure default HTTP header "Date" in Java Servlet? I want to change timezone from GMT to EET. Default header is for example:

Fri, 18 Sep 2015 06:28:36 GMT

I can set header value in response with setDateHeader(String name, long date); method. But I think it would be more efficient to set the timezone globally (I mean the scope of existing project). How can I do that? I'm using "Glassfish 4.1" server.

Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117
  • 2
    If you set the timezone globally in the JVM that should do the trick. Otherwise a `Filter` that sets the `Date` header correctly might be the simplest solution. – Boris the Spider Sep 18 '15 at 06:48
  • 1
    Check out this [other SO question](http://stackoverflow.com/q/1325075/2071828). It also recommends a filter, but one that sets the default `TimeZone`. But see also [this Sun bug](http://bugs.java.com/view_bug.do?bug_id=6352812). – Boris the Spider Sep 18 '15 at 08:50
  • Hmm.., I think it should be some settings in Glassfish globally, or in Web project. To filter every time when request is processed it is not efficient I think. After all - it is not a big problem, I can leave GMT.. But it would be nice to have such control. – Ernestas Gruodis Sep 18 '15 at 09:08
  • 1
    I think this is a limitation in the **terrible** Java Date/Time API (rectified in Java 8 somewhat). It's JVM global unless you do not have privileges to set `user.timezone` in which case it becomes thread local. The `Filter` approach is the most common - combined with a session local time zone variable. So you can start the server with `-Duser.timezone=...` and set it globally for the server, or battle with filters. – Boris the Spider Sep 18 '15 at 09:10

0 Answers0