The servlet below displays the date/time when it is accessed on the browser.

Java Code:
import java.io.*; 
import java.util.*; 
import javax.servlet.*; 
import javax.servlet.http.*; 
  
/** Simple Hello World Servlet 
 */ 
public class HelloServlet extends HttpServlet{ 
public void doGet(HttpServletRequest request, 
HttpServletResponse response) throws IOException { 
		PrintWriter out = response.getWriter(  ); 
		response.setContentType("text/html"); 
		out.println("<H1>Hello from a Servlet</h2>"); 
		out.println("<P>This servlet ran at "); 
		out.println(new Date().toString(  )); 
		out.println("<P>Courtesy of HelloServlet.java 1.2 "); 
	} 
}