One. The server recorded the website to be hicked and displayed on the customer browser
Import javax.servlet. *;
Import javax.servlet.http. *;
Import java.io. *;
Import java.util. *;
Public Class HitcountServlet Extends Httpservlet
{
Static int count;
All initialization code of // servlet, called when the servlet is loaded in the first time
Public Void Init (ServletConfig Config) Throws ServleTexception
{
Super.init (config);
}
/ / Accept customer request, the default method is doget ()
Public void doget (httpservletRequest Req,
HTTPSERVLETRESPONSE RESP)
Throws servletexception,
Java.io.ioException
{
/ / Set the content sent in response to the customer's fluor, set to text type
Resp.SetContentType ("text / html");
// Text output flow
PrintWriter out = Resp.getwriter ();
COUNT ;
Out.println ("");
Out.println ("
Out.println ("
Out.println ("You are user number" string.valueof (count) "Visiting Our Web Site" "/ n") ;;
Out.println (" Body> HTML>");
}
/ * public string getServletInfo ()
{
Return "BasicServlet Information";
} * /
}
------ Server-side launch J2EE server
Configure deploytool, new New Application, New Web Component, HitcountWebContext is a WebContext name, Hitcount is the name of Component Alias
----- Enter http://127.0.0.1:8000/hitcountwebcontext/hitcount in the customer browser