Listing 2. Java Servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletOne extends HttpServlet {
int hits;
public void init(ServletConfig conf)
throws ServletException {
super.init(conf);
hits = 0;
}
public void service(HttpServletRequest req,
HttpServletResponse res)
res.setContentType("text/html");
ServletOutputStream os = res.getOutputStream();
os.print(
"<HTML><HEAD><TITLE>TestServlet - Apache/JServ</TITLE></HEAD>");
os.print(
"<H1>Apache/JServ Servlet Test number one</H1>");
os.print("Number of hits: ");
os.println(Integer.toString( ++hits ));
os.close();
}
}
Copyright © 1994 - 2019 Linux Journal. All rights reserved.