Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
7.3 Persistent Servlet State and Auto Reloading Pages
157
Listing 7.1  PrimeNumbers.java (continued)
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Some " + numDigits + " Digit Prime Numbers";
    out.println(ServletUtilities.headWithTitle(title) +
                "\n" +
                "

" + title + "

\n" +
                "

Primes found with " + numDigits +

                " or more digits: " + numCurrentPrimes +
                ".");
    if (isLastResult)
      out.println("Done searching.");
    else
      out.println("Still looking for " + numPrimesRemaining +
                  " more...");
    out.println("
    ");
    for(int i=0; i
      out.println("  
  • " + currentPrimes.elementAt(i));
  •     }
        out.println("");
        out.println("");
      }
      public void doPost(HttpServletRequest request,
                         HttpServletResponse response)
          throws ServletException, IOException {
        doGet(request, response);
      }
      // See if there is an existing ongoing or completed
      // calculation with the same number of primes and number
      // of digits per prime. If so, return those results instead
      // of starting a new background thread. Keep this list
      // small so that the Web server doesn't use too much memory.
      // Synchronize access to the list since there may be
      // multiple simultaneous requests.
      
      private PrimeList findPrimeList(Vector primeListVector,
                                      int numPrimes,
                                      int numDigits) {
        synchronized(primeListVector) {
          for(int i=0; i
            PrimeList primes =
              (PrimeList)primeListVector.elementAt(i);
            if ((numPrimes == primes.numPrimes()) &&
                (numDigits == primes.numDigits()))
              return(primes);
          }
          return(null);
        }
      }
    }
    Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
    Servlet and JSP training courses by book's author: courses.coreservlets.com.
    
    
    
    
    
    
    footer
    
    
    
    
    

     

     

     

     

     Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

    jsp web hosting

     

    Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

    Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved