Labs
We will create a new Dynamic Web Application which displays lotto numbers, and deploy it to Tomcat.
- Create a new Dynamic Web Project called
LotteryApp. - Select the option to generate the web.xml deployment descriptor.
- Configure the project to use Maven.
- Add the servlet-api dependency.
<dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> </dependencies> - Create a new servlet
com.example.lotto.servlets.LotteryServlet. - Be sure to extend
HttpServlet. -
Override
doGet(). -
Create a new HTML page, src/main/webapp/index.html. This will be the homepage of your web app.
-
Add a link to
numbersreading Get Lotto Numbers. -
Configure web.xml:
- index.html is the welcome file.
-
Map LotteryServlet to the URL
/numbers. -
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.
-
Your
LotteryServletclass will get PowerBall numbers from another class. -
Use
DynamicWebApps/com.example.lottery.powerball.PowerBallDrawing, which returns aPowerBallDrawingResultobject, or copy your PowerBall code. -
In your servlet, use the PowerBall classes to generate PowerBall numbers, and add the numbers to the response as HTML.
(Solution: LotteryAppSolution/)