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 –

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

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.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
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.
Server-Side Scripting with Java Server Page, JSP.
1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: IO *Standard Output *Formatting Decimal.
Three types of scripting elements: 1.Expressions 2.Scriptlets 3.Declarations Scripting elements.
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.
Cupertino, CA, USA / September, 2000First ICU DeveloperWorkshop1 Date/Time/Number Formatting Alan Liu Globalization Center of Competency IBM Emerging Technology.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
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.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
Chapter 2 Practice.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 26 Internationalization.
Chapter 12: Internationalization Processing Date and Time Processing Date and Time  Locale  Date  TimeZone  Calendar and GregorianCalendar  DateFormat.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Java Classes ISYS 350. Introduction to Classes Two basic uses of class: – 1. A class is a way to organize functions (methods) to perform calculations.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
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.
Nic Shulver, Date and Time in JSP Surely it must be easy? Many calendars exist. The year 2013 (“Gregorian” or “Western”) is also:
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Dates and Times. Slide 2 Introduction to Dates and Times (1) The DateTime data type is used to store dates and times There is a date part There is a time.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Garside, JAVA: First Contact, 2ed Java First Contact – 2 nd Edition Garside and Mariani Chapter 6 More Java Data Types.
Java Servlet ISYS 350. What is Java Servlet? It is a java class that serves a client request. Servlets are most often used to: Process or store data that.
1 Chapter 20 Internationalization. 2 Objectives F To describe Java's internationalization features (§ 20.1). F To construct a locale with language, country,
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
Server-Side Scripting with Java Server Page, JSP.
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Tutorial 11 1 JavaScript Operators and Expressions.
Working with Date and Time ISYS 475. How PHP processes date and time? Traditional way: – Timestamp Newer and object oriented way: – DateTime class.
Loops ISYS 350. Two Types of Loops while loop for loop.
Hashmap, date, exception Android Club Agenda Hashmap Date Exception handling.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
Loops ISYS 350. Two Types of Loops while loop for loop.
JSP java server pages.
Working with Date ISYS 350.
Java Class and Servlet ISYS 350.
Basic Utility Classes U Abd. Rohim, MT mailto:
14 Shipping Time App Using Dates and Timers
Chapter 14 Internationalization
Java String and Date ISYS 350.
AJAX and Java Servlet ISYS 350.
JavaScript Arrays Date
JSP Implicit Objects Implicit Objects in JSP are objects that are automatically available in JSP. request: The request object retrieves the values that.
Servlet Date Operations
Java Date ISYS 350.
Server-Side Scripting with Java Server Page, JSP
Server-Side Scripting with Java Server Page, JSP
AJAX and JSP ISYS 350.
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Working with DateTime Data
Time is not on my side.
Java Array ISYS 350.
Java Date ISYS 350.
Java Servlet ISYS 350.
Java Date ISYS 350.
AJAX and JSP ISYS 350.
Java Date ISYS 350.
Presentation transcript:

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 – 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( " ");

Compute Future Value: Process form with controls Created Using JSP Code: Note this page is a jsp page

JSP code to create the form Enter present value: <% 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( " "); double[] yearValues= {10,15,30}; String[] yearLabels={"10-year","15-year","30-year"}; out.println( "Select year: "); for (int i = 0; i <= yearValues.length-1; i++) { out.println(" " + yearLabels[i] + " "); } %>

JSP Code to process the form <% String myPV, myRate, myYear; myPV=request.getParameter("PV"); myRate=request.getParameter("Rate"); myYear=request.getParameter("Year"); double FV, PV, Rate, Year; PV=Double.parseDouble(myPV); Rate=Double.parseDouble(myRate); Year=Double.parseDouble(myYear); FV=PV*Math.pow(1+Rate,Year); out.println("FutureValue is:"+ FV); %>

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==string2) //if (string1.equals(string2)) //if (string1.equalsIgnoreCase(string2)) { out.println("The two strings are equal."); } else { out.println("The two strings are not equal."); }

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

Calculating Days between Current Date and Entered Date Using the getTime() method Enter a date:

computeDate.jsp <% Date currentDate = new Date(); Date myDate; DateFormat formatter = new SimpleDateFormat("MM/dd/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)+" "); %>