Server-Side Scripting with JSP (2) ISYS 350. Post Back A postback is call to the same page that the form is on. In other words, the contents of the form.

Slides:



Advertisements
Similar presentations
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
Advertisements

$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200.
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500.
PHP Form and File Handling
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 107.
$100 $400 $300$200$400 $200$100$100$400 $200$200$500 $500$300 $200$500 $100$300$100$300 $500$300$400$400$500.
Chapter 1 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
LIS651 lecture 3 functions & sessions Thomas Krichel
Problem Solving & Program Design in C
9 Copyright © 2005, Oracle. All rights reserved. Using Strings, String Buffer, Wrapper, and Text-Formatting Classes.
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
HIGHER GRADE CHEMISTRY CALCULATIONS Radioactivity and Half-Life Half-life is the time taken for half of a radioisotope to decay. This value is constant.
Instructions for Playing Jeopardy Click on the question that you want to attempt, example $100 Read the question and click on the slide to advance to.
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
Year 6 mental test 15 second questions Numbers and number system Numbers and the number system, Measures and Shape.
1 The Backlog Issue and the JPO's Effort Koichi Minami Deputy Commissioner Japan Patent Office.
Java
What Time Is It? Lesson by Mrs. Moody, FLE. M1M2 Students will develop an understanding of the measurement of time. a Tell time to the nearest hour and.
Teds Big Boy Restaurant 5000 People were surveyed to determine if there is enough demand for a new Teds Big Boy Restaurant in the west side of town.
Two Dimensional Arrays and ArrayList
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
15. Oktober Oktober Oktober 2012.
Category Category 2Category 3Category 4Category
$ TOTAL INCOME 100 Quick Start 4 Within 30 Days of Start Date.
Created by Susan Neal $100 Fractions Addition Fractions Subtraction Fractions Multiplication Fractions Division General $200 $300 $400 $500 $100 $200.
We are learning how to read the 24 hour clock
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Equal or Not. Equal or Not
Slippery Slope
Blank Jeopardy. Category #1 Category #2 Category #3 Category #4 Category #
 A string is an array of characters.  Strings must have a 0 or null character after the last character to show where the string ends.  The null character.
Select a time to count down from the clock above
More on Processing User Input BCIS 3680 Enterprise Programming.
01. Consider the following code segment. int x = int n = 0; if (x < 500) { if (x > 750) n = 100; else n = 200; } else { if (x < 300) n = 300; else n =
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Chapter 25 JavaServer Pages and Servlets. CHAPTER GOALS To implement dynamic web pages with JavaServer Pages technology To learn the syntactical elements.
Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Chapter 12: Internationalization Processing Date and Time Processing Date and Time  Locale  Date  TimeZone  Calendar and GregorianCalendar  DateFormat.
Server-Side Scripting with JSP (2) ISYS 350. Post Back A postback is call to the same page that the form is on. In other words, the contents of the form.
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Garside, JAVA: First Contact, 2ed Java First Contact – 2 nd Edition Garside and Mariani Chapter 6 More Java Data Types.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Hashmap, date, exception Android Club Agenda Hashmap Date Exception handling.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Working with Date ISYS 350.
Java String and Date ISYS 350.
Servlet Date Operations
Java Date ISYS 350.
Java Date ISYS 350.
PART 2.
Java Date ISYS 350.
Java Date ISYS 350.
Presentation transcript:

Server-Side Scripting with JSP (2) ISYS 350

Post Back A postback is call to the same page that the form is on. In other words, the contents of the form are POSTed back to the same URL as the form. If a page is opened because of a postback, then it is not opened for the first time. – First time: present an empty form – Post back: present the results.

Use a JSP to Presenting Form and Handle the Form Use the form’s action attribute to call the JSP program itself. Use a hidden element to indicate that the type is post back: – – The JSP program checks to see if the JSP program is called for the first time or not. If it is a postback, then the JSP program processes the data submitted by the form

When the page is first loaded, IsPostBack will have a null value because the page has not posted back yet.

JSP testing for null value if (user_id ! = null) { Out.println (user_id); }

Use JSP to Present and Process a Form

sumPage.jsp <% String value1, value2; double n1=0, n2=0, sum=0; if (request.getParameter("IsPostBack")!=null) { value1=request.getParameter("num1"); value2=request.getParameter("num2"); n1= Double.parseDouble(value1); n2= Double.parseDouble(value2); sum=n1+n2; %> Value1: "> Value2: "> Sum is: "> <% } else { %> Value1: Value2: Sum is: <% } %>

sumPage.jsp <% String value1, value2; double n1=0, n2=0, sum=0; if (request.getParameter("IsPostBack")!=null) { value1=request.getParameter("num1"); value2=request.getParameter("num2"); n1= Double.parseDouble(value1); n2= Double.parseDouble(value2); sum=n1+n2; } %> Value1: "> Value2: "> Sum is: ">

Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 – double[] anArrayOfDoubles = new double[10]; – String[] anArrayOfStrings = new String[10]; – int[] anArray = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};

Creating a listbox of rates double[] rates= {0.03,0.04,0.05,0.06,0.07}; String[] displays={"3%","4%","5%","6%","7%"}; out.println( "Select interest rate: "); for (int i = 0; i < rates.length-1; i++) { out.println(" " + displays[i] + " "); } out.println( " ");

Testing if two strings are equal The equals() or equalsIgnoreCase method should be used to determine whether two objects have the same values. String string1 = "foo"; String string2 = “Foo"; if (string1.equals(string2)) //if (string1.equalsIgnoreCase(string2)) { out.println("The two strings are the same.") }

Java Date Processing: Date Class Date class: – Define a date object: Date myDate; – Define a date object with the current date: Date currentDate = new Date(); – getTime method: return the date in milliseconds since 1/1/1900

Java Date Processing: DateFormat class DateFormat class is used to define a date format to display a date object or parsing a date/time string to create a date object. Define a date format: – DateFormat formatter = new SimpleDateFormat("dd/MM/yy"); To print a data object: – out.print("Current date is: " + formatter.format(currentDate)); To parse a date string: – myDate=formatter.parse(request.getParameter("txtDa te"));

Import Java Class Example: Display Current Date Time Import java.util.Date – Define a Date type variable: – Date currentDate = new Date(); Display in textbox using JSP expression: The time is: ">

Date to Date Format Import class: – – Define a format: SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy"); – Convert: Example: Display a date with date format: String displayDate = formatter.format(currentDate);

Define Date Format Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 1996; 96 M Month in year Month July; Jul; 07 w Week in year Number 27 W Week in month Number 2 D Day in year Number 189 d Day in month Number 10 F Day of week in month Number 2 E Day in week Text Tuesday; Tue a Am/pm marker Text PM H Hour in day (0-23) Number 0 k Hour in day (1-24) Number 24 K Hour in am/pm (0-11) Number 0 h Hour in am/pm (1-12) Number 12 m Minute in hour Number 30 s Second in minute Number 55 S Millisecond Number 978 z Time zone General time zone Pacific Standard Time; PST; G MT-08:00 Z Time zone RFC 822 time zone -0800

Example Enter a date:

computeDate.jsp <% Date currentDate = new Date(); Date myDate; DateFormat formatter = new SimpleDateFormat("dd/MM/yy"); myDate=formatter.parse(request.getParameter("txtDate")); out.print(currentDate +" "); out.print("Current date is: " + formatter.format(currentDate)+" "); out.print("Entered date is: " + formatter.format(myDate)+" "); out.print ("Days between = " + (currentDate.getTime()- myDate.getTime())/(24*60*60*1000)+" "); DateFormat yearFormat=new SimpleDateFormat("yyyy"); DateFormat monthFormat=new SimpleDateFormat("MM"); DateFormat weekDayFormat=new SimpleDateFormat("E"); out.print(yearFormat.format(currentDate)+" "); out.print(monthFormat.format(currentDate)+" "); out.print(weekDayFormat.format(currentDate)+" "); %>