Labs

We will create a new Dynamic Web Application which displays lotto numbers, and deploy it to Tomcat.

  1. Create a new Dynamic Web Project called LotteryApp.
  2. Select the option to generate the web.xml deployment descriptor.
  3. Configure the project to use Maven.
  4. Add the servlet-api dependency.
    <dependencies>
       <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>javax.servlet-api</artifactId>
           <version>3.1.0</version>
       </dependency>
    </dependencies>
    
  5. Create a new servlet com.example.lotto.servlets.LotteryServlet.
  6. Be sure to extend HttpServlet.
  7. Override doGet().

  8. Create a new HTML page, src/main/webapp/index.html. This will be the homepage of your web app.

  9. Add a link to numbers reading Get Lotto Numbers.

  10. Configure web.xml:

  11. index.html is the welcome file.
  12. Map LotteryServlet to the URL /numbers.

  13. Run your web app on Eclipse's Tomcat Server. Issues are likely mapping or file locations. Make sure index.html is in the src/main/webapp folder.

  14. Your LotteryServlet class will get PowerBall numbers from another class.

  15. Use DynamicWebApps/com.example.lottery.powerball.PowerBallDrawing, which returns a PowerBallDrawingResult object, or copy your PowerBall code.

  16. In your servlet, use the PowerBall classes to generate PowerBall numbers, and add the numbers to the response as HTML.

(Solution: LotteryAppSolution/)


Prev -- Up -- Next