Create an application to display current date and time in apache tomcat server

Here is the code to display current date and time in the apache tomcat server.

  1. Create a landing page.

Index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Practical Work</title>
</head>
<body>
<form action="perform_something.jsp">

  <button type="submit">Click here to know current date and time</button><br/> </form>
</body>
</html

2. To show the current date and time, use Java date object in a JSP page.

Perform_Something.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.Date"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Date da = new Date();

%>
Date:<%= da.toLocaleString() %>
</body>
</html>

Output:

 display current date in jsp

 

 

display current date in jsp 1

Leave a Reply