



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Write a GraphicsProgram that does the following:
the display should look like this:
specified direction. At the same time, your code should add a red GLine that connects the old and new locations of the pen.
Keep in mind that each button click adds a new GLine that starts where the previous one left off. The result is therefore a line that charts the path of the cross as it moves in response to the buttons. For example, if you clicked East, North, West, North, and East in that order, the screen would show a Stanford “S” like this (note the "S" would be red, even though it does not appear so in the black and white handout):
In this question you will develop a Web application that performs simple calculation. The application with require these files: ─ calculatorUI.html which will contain the user input form for the application. ─ result.jsp which will display the result of the calculation. ─ CalculatorBean.java which is the Java bean used by result.jsp to obtain the calculated result. ─ CalculatorServlet.java which will initialize CalculatorBean and forward the request. ─ web.xml which is the deployment descriptor for the servlet. Task One: Creating the Web Context Directory Structure
This directory structure is used by Java Application Servers to represent a web context.
The mod14lab directory will contain our HTML and JSP pages. WEB-INF will contain the web.xml deployment descriptor. The lab14 directory will contain our classes and is where we will compile our code.
Compiling the source code for this lab requires a CLASSPATH to servlet-api.jar. This jar file contains the classes required to compile servlets. It has been supplied and is available in the c:\labs\lib directory. Use the following to compile: javac – cp .;c:\labs\lib\servlet-api.jar *.java Tomcat includes this jar file so we do not need to deploy it with our application. Task Two: Create the User Interface View calculatorUI.html will be used to display our UI. It should look like the screen capture below:
Calculator UI
Our business logic will need to test the value of the operator variable and perform the appropriate math. This can be done using if and else if branching. Enter the code to accomplish this. Task Four: Creating the Servlet Controller
http://localhost:8080/mod14lab The calculatorUI.html page should be displayed as shown in Step Two. Enter numbers in the text fields and click Submit. You should see the message coded in the skeleton result.jsp. Task Five: Displaying Results At this point, we should have four files:
mod14lab/WEB-INF/classes/lab14/CalculatorBean.java: if this class is not done, complete it now. Refer to Part Three of this lab.
mod14lab/WEB-INF/classes/lab14/CalculatorServlet.java: if this class is not done, complete it now. Refer to Part Four of this lab. mod14lab/calculatorUI.html: this document should be done. Refer to Part Two of this lab.
mod14lab/result.jsp: this document will require the most work. Complete it by following the steps listed below:
It should be remembered that the property does not refer to the variable, but to the getMethod() for that property. It follows that the getResult() method of our bean is understood to represent a variable named result. This allows us to introduce a method that contains only business logic that acts on the first and second variables to perform the calculation.
Back
To test your application, stop Tomcat. Delete the mod15lab the directory under Tomcat’s webapps directory (and the C:\work\Catalina\localhost\mod14lab directory to be sure the bug doesn’t surface)