Display time on JSP page

This was my line in demo.jsp demo

Hello! Time is <% = new java.util.Date ()%>

which, when I opened in firefox, does not show time. instead, displays the same line: "Time is <% = new java.util.Date ()%>"

+3
source share
3 answers

Your code is completely correct, it will display the current time, formatted according to the current locale settings. As others point out incorrectly, the position of where you put this on the page (i.e., surrounded by other HTML tags) is not a problem here.

, , (://yourPath/demo.jsp), - (, Apache), (, Tomcat, Jetty,..), <% -% > JSP System.

Tomcat Jetty , JSP , Eclipse IDEA.

+4

, <% = new java.util.Date()% > , , :

<td width="100%"><b>&nbsp;Current  Date 
and time is:&nbsp; <font color="#FF0000">


<%= new java.util.Date() %>
</font></b></td>

, .

: http://www.roseindia.net/jsp/jsp_date_example.shtml

Dave

+3

, , , . . "" JSP 1.2.

Another recommendation: Explore JSTL and use format tags to properly format the time and date. Do not use scripts.

0
source

Source: https://habr.com/ru/post/1704575/


All Articles