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

Java Code:
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(  ); 
		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 1.2 ");