Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
46
Chapter 2 First Servlets
Listing 2.11 LotteryNumbers.java 
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Example using servlet initialization and the
 *  getLastModified method. 
 */
public class LotteryNumbers extends HttpServlet {
  private long modTime;
  private int[] numbers = new int[10];
  /** The init method is called only when the servlet
   *  is first loaded, before the first request
   *  is processed.
   */
  
  public void init() throws ServletException {
    // Round to nearest second (ie 1000 milliseconds)
    modTime = System.currentTimeMillis()/1000*1000;
    for(int i=0; i
      numbers[i] = randomNum();
    }
  }
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Your Lottery Numbers";
    out.println(ServletUtilities.headWithTitle(title) +
                "\n" +
                "

" + title + "

\n" +
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