Chapter 4 Handling the Client Request Form Data







































- Slides: 39
Chapter 4 Handling the Client Request: Form Data
Contents A. B. C. D. Body Mass Index Problem Currency Exchange Problem Tuition Calculation Problem Mark Converter Problem
n Where weight (in kilogram) and height (in meter) are real numbers representing the weight and the height of a person. The result should be rounded with one decimal place.
Solution 1. 2. 3. 3. Developing the view Developing the Model: BMI Developing the Controller: BMI Servlet Running The Application
1. Developing the view User Microsoft Front Page or Macromedia Dreamweaver to design this interface: Name: weight. Text. Box Name: height. Text. Box Name: calculate. BMIButton
n n n Page name: bmi. html Page title: Body Mass Index Table: n Row 1: n n n Row 2: n n n Label: weight Textbox named: weight. Text. Box Label: height Textbox named: height. Text. Box Row 3: button named calculate. BMIButton
2. Developing the Model: BMI
3. Developing the Controller: BMI Servlet n Specify the action for the bmi_interface. html view:
3. Running The Application n n Make sure the bmi_interface. html file is in Web. Content folder. Right click this file -> Run as -> Run on server.
Exercise § § Upgrade the above problem to display Weight status The following table are the definitions of BMI categories for adults used by the WHO: BMI Below 18. 5 - 24. 9 25. 0 - 29. 9 Weight Status Underweight Normal Overweight 30. 0 and Above Obese
B. Currency Exchange Problem n Develop a web program allows users to input VND and choose either USD or EUR as well as JPY to exchange. Following table is the exchange rates from VND: Currency Exchange Rates USD 16, 452 EUR 25, 170. 38 JPY 151. 23
Solution 1. Developing the view 2. Developing the Model: Currency Exchange 3. Developing the Controller: Currency Exchange Servlet
1. Designing the view n User Microsoft Front Page or Macromedia Dreamweaver to design this interface: Name: vnd. Text. Box Name: des. Currency. Radio Name: exchange. Button
n n n Page name: currency_exchange. html Page title: Currency Exchange Table: n Row 1: n n Label: VND Textbox named vnd. Text. Box Row 2: three radio buttons named des. Currency. Radio, values: USD, EUR, JPY Row 3: button named exchange. Button
2. Developing the Model: Currency. Exchange
3. Developing the Controller: Currency. Exchange. Servlet n Specify the action for the view: currency_exchange. html
C. Tuition Fee Calculation Problem n n Given the cost of AAS course is $120, ESL course is $75. Developing a web program calculate the tuition of a student when knows number of AAS, ESL courses and type of student. Type of student can be Normal (0% discount), 10$ discount, 20% discount or 50% discount.
Solution 1. Developing the view 2. Developing the Model: Tuition Calculation 3. Developing the Controller: Tuition Calculation Servlet
1. Developing the view Name: aas. Text. Box Name: esl. Text. Box Name: calculate. Button Name: discount. Rate. Select. Box
n n n Page name: tuition_calculation. html Page title: Tuition Calculation Table n Row 1: n n Label: Number of AAS course(s) Textbox named: aas. Text. Box Label: ($120) Row 2: n n n Label: Number of AAS course(s) Textbox named: aas. Text. Box Label: ($120)
n Row 2: n n Label: Number of ESL course(s) Textbox named: esl. Text. Box Label: ($75) Row 3: n n Label: Type of Student Select box n named discount. Rate. Select. Box Value: n 0: Normal n 10: 10% Discount n 20: 20% Discount n 50: 50% Discount Row 4: button named calculate. Button
2. Developing the Model: Tuition Calculation
3. Developing the Controller: Tuition Calculation Servlet n Specify the action for the tuition_calculation. html file
D. Mark Converter Problem n Develop a web program to convert Mark to Grade and Point, with: n n Mark: from 0 to 100 Grade: n n n 90 -100 mark : A 80 – 89 mark: B 70 – 79 mark: C 60 – 69 mark: D 0 – 59 mark: F
n Point: n n n 90 -100 mark : 4 80 – 89 mark: 3 70 – 79 mark: 2 60 – 69 mark: 1 0 – 59 mark: 0
Solution 1. Developing the view 2. Developing the Model: Mark Converter 3. Developing the Controller: Mark Converter Servlet
1. Developing the view Name: mark. Text. Box Name: grade. Check. Box Name: point. Check. Box Name: convert. Button
n n n Page name: mark_converter. html Page Title: Mark Converter Table: n Row 1 n n n Row 2: n n n Label: Mark in percent Textbox named mark. Text. Box Checkbox named: grade. Check. Box, value: Grade Checkbox named: point. Check. Box, value: Point Row 3: button named convert. Button
2. Developing the Model: Mark Converter
3. Developing the Controller: Mark Converter Servlet
n Specify the action for the view mark_converter. html
Exercise n Develop a program receive midterm (30%), final (30%) and project (40%) marks then calculate and displays the results. Which result can be: n n Average mark Grade: A, B, C, D, F Point: 4, 3, 2, 1, 0 Result: n n Average >= 60: pass Average < 60 : fail
References 1. Core Servlets And Java Server Pages, Volume 1, 2 nd Edition, Chapter 4