5 Aug 2012

JSTL Date Format and Search Engines

This post is about an interesting bug I ran into in our web app at work. We have a traditional web app (spring web mvc, hibernate, etc) and use JSPs for our presentation layer. We currently provide a REST interface with JSON allowing access to certain data services internally in the company I wont give out the exact details, however one of the web services prints out the following information
{ "id": 1234, "name": "John Doe", "lastModified": "2012-03-03 14:40"}
The interesting part in this scenario is the last modified date, returned in the format "yyyy-MM-dd HH:mm" in GMT time.

The service itself is quite old and we hadn't had any problems with it until a new client was being developed and wanted to use this service. When the new client was hitting the service it was returning the wrong date format.

The JSP view had the following:
{ "id": ${object.id}, "name": ${object.name}, "lastModified":<fmt:formatedate pattern="yyyy-MM-dd HH:mm" values="${object.lastModified}" /> }
Digging through apaches implementation of the tag I found something interesting.

If a web request was to come in without the request header Accept-Language: <LANG>. The implementation will call the toString method of the date object. Interestingly enough, search engines don't send this either so beware.

No comments:

Post a Comment