Yehonatan
Yehonatan

Reputation: 1172

Java dynamic page title

I've just been given the task of updating a web page in an enterprise java web app to include the date in the page title.

Currently the web page is a static html file - what do i need to do to get the page title to be the current date in YYYY/MM/DD format? Sorry I have no idea where to start!

Upvotes: 3

Views: 488

Answers (2)

Veerana Bhuya
Veerana Bhuya

Reputation: 46

<script language="Javascript" type="text/javascript">
alert(document.title);
document.title = (new Date()) + " --- " + document.title;
</script>

Upvotes: 3

Tomas Narros
Tomas Narros

Reputation: 13468

You have two options:

  1. Update the page title with Javascript at the body onload event.
  2. Become this static HTML file into a JSP dinamic page.

Depending on your requirements, the first option will imply less changes. With the first option, you will take the browser date, with the second, you will use the server system date. This could be important if your application is to be accessed from different time zones.

Upvotes: 1

Related Questions