FileDocCategorySizeDatePackage
ChainCounter.javaAPI DocExample1305Tue Jan 25 10:45:14 GMT 2000None

ChainCounter

public class ChainCounter extends GenericCounter

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)


    String contentType = req.getContentType();
    res.setContentType(contentType);

    PrintWriter out = res.getWriter();

    // Fetch the page we're on.
    String uri = req.getRequestURI();

    // Get and increment the count
    int count = incrementAndGetCount(uri);

    // Prepare to read the input
    BufferedReader reader = req.getReader();

    String line = null;
    while ((line = reader.readLine()) != null) {
      line = replace(line, "<COUNT>", "" + count);  // case sensitive
      out.println(line);
    }
  
public voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    doGet(req, res);
  
private java.lang.Stringreplace(java.lang.String line, java.lang.String oldString, java.lang.String newString)

    int index = 0;
    while ((index = line.indexOf(oldString, index)) >= 0) {
      line = line.substring(0, index) +
             newString +
             line.substring(index + oldString.length());
      line += newString.length();
    }
    return line;