import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class FirstAccessed extends HttpServlet{
private Date first;
private int count;
public void init() throws ServletException {
// Enter the time/date when the server calls this servlet and
// initialize counter
first = new Date();
count = 0;
return;
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
int local_count;
synchronized(this) {
local_count = ++count;
}
out.println("<HTML>");
out.println("<HEAD><TITLE>First Accessed Servlet</TITLE></HEAD>");
out.println("<BODY>");
out.println("This servlet was first loaded by the server at " + first);
out.println("<br>The current time is " + new Date());
out.println("<br>");
out.println("This servlet has been accessed " + local_count + " times.");
out.println("</BODY></HTML>");
}
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.