Web Programming: Loop Xiaozhong Liu

Slides:



Advertisements
Similar presentations
COMP 321 Week 8. Overview MVC Example Servlet Lifecycle Servlet Mechanics MVC Lab 5-2 Solution Lab 8-1 Introduction.
Advertisements

Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Servlets Stoney Jackson
JSP Java Server Pages Reference:
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Proposed 1 Modify the count servlet in order to generate an answer showing the IP addresses of ALL computer that have accessed it –Use a vector or an array.
27-Jun-15 Directories and DDs. 2 Web apps A web application is basically a web site that: “Knows who you are”--it doesn’t just give you static pages,
Servlets Replace Common Gateway Interface Scripts Extend Server Functionality Modules (software components) Like applets to browsers No GUI.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
A Servlet’s Job Read explicit data sent by client (form data) Read implicit data sent by client (request headers) Generate the results Send the explicit.
Java Servlet. What is Java Servlet? A Servlet is a java based server side web technology. It is a java class that serves a client request and receives.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets and JSP.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
CSC 2720 Building Web Applications
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Java Servlets. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Java Servlets & Java Server Pages Lecture July 2013.
Slides © Marty Hall, book © Sun Microsystems Press 1 Handling the Client Request: Form Data Core Servlets & JSP book:
Saving Client State Session Tracking: Maintain state about series of requests from same client over time Using Cookies: Clients hold small amount of their.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
Top right corner for field-mark, customer or partner logotypes. See Best practice for example. Slide title 40 pt Slide subtitle 24 pt Text 24 pt Bullets.
Hints for Assignment #8. Initial Screen Hints for the initial page You need a DOCTYPE with the proper namespaces defined You need to import the facebook.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Introduction to Servlets. Introduction Servlet is a language to develop the server side applications, and it is also server side component. It can develop.
J2EE T ECHNOLOGIES These are the technologies required to build large scale distributed applications, can be divided into – Component Technologies eg.
S517 Web Programming Assistant Professor Xiaozhong Liu
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Introduction To HTML Dr. Magdi AMER. HTML elements.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
Web Programming Assistant Professor Xiaozhong Liu
J2EE/Java EE Apache Tomcat v9 IBM Websphere v8 Redhat JBoss EAP v6 Oracle Weblogic v12 Fusion Web Tier ServletsJSPJSF Business Tier JMXJMSEJB.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Decisions: Conditional Statements (informally called If Statements) IST 256 Application Programming for Information Systems.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
Web Programming: If Statement and Servlet
Net-centric Computing
Servlets Hits Counter 20-Jul-18.
Session Tracking in Servlets
HTTP request message two types of HTTP messages: request, response
SERVLETS AND JDBC.
Servlet.
Introduction to Application Programming
Jagdish Gangolly State University of New York at Albany
Servlets and Java Server Pages
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
In Class Assg 2 - solution
© copyright Janson Industries 2011
Web Search Interfaces.
Web Search Interfaces by Ray Mooney
Servlets.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Directories and DDs 25-Apr-19.
Basic servlet structure
Directories and DDs 21-Jul-19.
Servlets: Servlet / Web Browser Communication I
Directories and DDs 14-Sep-19.
Presentation transcript:

Web Programming: Loop Xiaozhong Liu

Mario problem Mario player = new Mario(); //hit a special brick if (player.status.equals(“small”)) { show_mushroom(); } else { show_flower(); }

Mario problem Mario player = new Mario(); //Mario change if (get_mushroom()) { player.status = “big”; } if (get_flower()){ player.status = “shoot”; } if (get_hurt() && player.status.equals(“big”)) { player.status = “small”; } if (get_hurt() && player.status.equals(“small”)) { player.status = “die”; }

Example 1 If your age > 20, serve you wine; else, serve you soda… int age; String drink; age = ??; if (age > 20) { drink = “wine”; } else { drink = “soda”;}System.out.println(drink);

Practice 3 Shopping problem. Suppose that there is a String variable called PayStatus that is either “Hourly” or “Salaried”, and that we want to compute the Pay of an employee using a variable Hours that tells how many hours they worked that week, and the variable PayRate that tells how much per hour that they make. Salaried employees are always paid as if they worked 40 hours, no matter how many hours they actually worked. If hourly employees work more than 40 hours in a week, then they get 1.5 times their pay rate for any hours over 40.

Sum of: ……… int result = 0; result = result + 1; result = result + 2; result = result + 3; …… result = result + 100; System.out.println(result);

Sum of: ……… int result; result = 0; for (int i = 0; i <= 100; i = i + 1) { result = result + i; } System.out.println(result);

int result; result = 0; for (int i = 0; i <= 100; i = i + 1) { result = result + i; } System.out.println(result); for (initialization; condition; change) Life cycle of variable i

Initialization Loop Body Condition? Increment no yes int i = 1 result = result + i; i <= 100? i ++ no yes Example

Sum of: ……….. + ??? Result more than 1000 int result = 0; int number = 0; while (result < 1000) { number = number + 1; result = result + number; } System.out.println(number); Initialize Testing Change

Compare for (int i = 0; i <= 100; i = i + 1) { result = result + i; } while (result < 1000) { number = number + 1; result = result + number; }

For or While? 1.Compute 25! (factorial) 2. Save $1000 in the bank, interest rate is 3.5%. How many years? total = $ Send messages to your facebook friends automatically

Web Programming<html><head> Compute test Compute test Please submit your information Please submit your information First number: First number: </tr> Second number: Second number: </td></tr><tr> </tr></table></form></body></html>

Web Programming protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println(" "); out.println(" Compute test "); out.println(" Please submit your information "); out.println("<form method=\"post\" action =\"" + request.getContextPath() + "/web_coompute\" >"); out.println(" "); out.println("First number: "); out.println(" "); out.println("Second number: "); out.println(" "); }

Web Programming protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub Enumeration paramNames = request.getParameterNames(); response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println(" "); out.println(" Result "); out.println(" Compute result: "); int firstnum = Integer.parseInt(request.getParameter("firstnum")); int secondnum = Integer.parseInt(request.getParameter("secondname")); int sum = firstnum + secondnum; out.println(Integer.toString(sum)); out.println(" "); }

Web Programming protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println(" "); out.println(" Result "); out.println(" Compute result: "); int firstnum = Integer.parseInt(request.getParameter("firstnum")); int secondnum = Integer.parseInt(request.getParameter("secondname")); int sum = firstnum + secondnum; out.println(Integer.toString(sum)); out.println(" "); }