More on Processing User Input BCIS 3680 Enterprise Programming.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
The World Wide Web. 2 The Web is an infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that.
Chapter 61 Processing the Client Request JavaServer Pages By Xue Bai.
Introducing JavaScript
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Tutorial 12: Enhancing Excel with Visual Basic for Applications
The Web Warrior Guide to Web Design Technologies
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
DT228/3 Web Development JSP: Directives and Scripting elements.
Course Textbook: Build Your Own ASP.Net Website: Chapter 2
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Introduction to Python
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
JSP Java Server Pages Softsmith Infotech.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
Chapter 8 Cookies And Security JavaScript, Third Edition.
1 JavaScript in Context. Server-Side Programming.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
Using Client-Side Scripts to Enhance Web Applications 1.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
Web App GUI: JSP Basics & Forms 3680 Enterprise Programming.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
XP Tutorial 8 Adding Interactivity with ActionScript.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
Basic XHTML Tables XHTML tables—a frequently used feature that organizes data into rows and columns. Tables are defined with the table element. Table.
Introduction to Scripting
Introducing Forms.
Java Server Pages.
WEB PROGRAMMING JavaScript.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 10: Programming with javascript
Web Programming and Design
Presentation transcript:

More on Processing User Input BCIS 3680 Enterprise Programming

Overview 2  More input fields  More JSP elements  Scriptlet  Declaration  Directive  Useful techniques  Session variables  Redirecting traffic  Comparing strings

Processing User Input  Again, each piece of user input is passed as a parameter.  Just like with servlets, use getParameter() method to retrieve the value for a parameter.  Be very careful with parameters that may be passed as null (e.g., checkboxes), or textboxes that can’t be made mandatory according to business logic).  If user enters a value, it is passed as a String (with exact capitalization as entered by the user). If user skips a value (and your business logic allows it), it is passed as a null object.  A checkbox is an optional item. So if it is not checked and you try to get it as a parameter, you will get a null object. 3

Dropdown List 4  Use the element to create a dropdown list.  The “ name ” attribute is its unique identifier that distinguishes it from other controls.  Each selectable item is defined in an element, which is a “child” element of.  The item that is selected by default is marked by the “ selected ” attribute.  The corresponding parameter has:  A name that comes from the name attribute of the element;  A value that comes from the value attribute of the element selected by the user.

Dropdown List 5 State: Texas Florida California

Hidden Input 6  Hidden input also is created with the element.  Set the “ type ” attribute to “ hidden ”.  It does not appear anywhere in page display, but the element is visible in the HTML source of the page.  Use it only to pass information that would become a distraction or cause confusion for the user if it is displayed.  Don’t use it to hide any data that may cause privacy concern. <input type="hidden" name="agent" value= "007" /input>  This will pass the name-value pair “ agent=007 ” to the “ action ” page.

Textarea 7  The element of “ text ” type creates a single- line input box for textual information.  To have multi-line text boxes, use the element instead.  Define the number of rows and columns you want. Comments:

Review: JSP Elements ElementOpening & Closing Tags Description Expression <%= %> Segment of Java statement that resolves to a String value. Scriptlet <% %> One or more complete Java statements grouped together logically. Declaration <%! %> Equivalent to a method in a Java class. Directives %> Special instructions; e.g., The “ import ” attribute of the “ page ” directive is equivalent to the import statement in Java. 8

Declaration  To make your code more modular like that in a Java class, you can use the declaration to define methods inside a JSP file.  Now not only can your JSP expressions refer to variable names, but also make method calls.  This provides more flexibility in how you mix JSP expressions and HTML code. 9

Directive   For now we’re only interested in the page and include directives.  The page directive has an import attribute that is equivalent to the import statement in Java.  The import=value pair is only one attribute. Therefore, to import more than one class, all classes must be included within one pair of quotation marks, separated by commas.  The include directive can be used to attach the same header and footer to a number of pages. 10

The import Attribute 11  Make Java classes available to the scripting environment.  Use Java API to add power to your JSP script.  When a Java class is imported to a JSP page, you can reference this class without explicitly specify the class package names.  Syntax  Similar to the import statement in Java.

Location of User-Defined Classes 12  To use those classes that ship with the Java language, the import attribute of the pag e directive is sufficient.  To use custom made classes, additional work is needed:  First, compile the class from source code into a.class file.  In the deployment folder, create a “ WEB-INF ” subfolder.  Inside WEB-INF, create a “ classes ” subfolder.  Inside classes subfolder, create a subfolder whose name is the same as the name of the package to which the class belongs. For example, “ unt ” subfolder if the class belongs to the “ unt ” package.  If the package name is hierarchical, the subfolder structure should mirror that hierarchy. For example, store the class files for the wu.andy package in \WEB- INF\classes\wu\andy.

Include Files 13  Usage  Provide the same navigation links and footer on each of the pages.  Reuse JSP code.

14 The include Directive  When the JSP page containing the include directive is requested for the first time, the content of the included file is read and merged with the rest of the JSP page.  The order matters. For example, if the include directive is placed after the tag of the JSP page, the words enclosed by that tag is displayed in the title bar. If the include directive appears before the tag, then the included page’s title takes precedence.  After the JSP page has been displayed, updating the included file has no impact on the JSP page.

Comparing Strings  When used with two strings, the equality operator compares the memory locations of the strings.  The comparison methods compare text. They do not compare the memory locations marked by the two references to the strings.  The addresses are certainly different, unless you assign one to the other.  That’s why we cannot compare the texts stored in two strings by something like: if ( str1 == str2 ). This boolean expression compares the memory locations of str1 and str2, not the texts.  Normally, we simply want to compare the literal values contained in two strings (and by extension, in two memory locations), but not the memory locations themselves. 15

Comparing Strings 16 ComparisonWhat Are ComparedPractical Use Using equals() or equalsIgnoreCase() The texts (literal values) stored in the two memory locations allocated to the two strings. Very useful in business applications Using the equality operator ( == ) The memory locations of the two strings (always different even though they may contain the exact same text). Rarely useful in business applications

Comparing Strings  A common task in text processing is to compare two strings and see whether they are identical.  If the comparison is case sensitive (namely, “BCIS” is considered different from “bcis”):  Use the equals() method of the String class.  If the comparison is case insensitive (namely, “BCIS” is considered the same as “bcis”):  Option 1: Use the equalsIgnoreCase() method.  Option 2: Convert both strings into the same case (using either toUpperCase() or toLowerCase() method) and then use the equal() method to compare them. 17

Methods Involved in Comparison 18 Return typeSignature booleanequals( String str ) Evaluates to true if the calling string is the same as str, case-sensitive; returns false otherwise. booleanequalsIgnoreCase( String str ) Evaluates to true if the calling string is the same as str, case-insensitive; returns false otherwise. StringtoUpperCase() Converts all the letters in the calling string to upper case. StringtoLowerCase() Converts all the letters in the calling string to lower case.

Redirecting Traffic 19  Sometimes, you may want to display different pages to the user, depending on his or her input from the previous page.  Retrieve the value of the criterion from the related parameter.  Evaluate the parameter and determine which URL to use.  If another page instead of the current page should be displayed, call the sendRedirect() method of the response object, using that page’s file name or URL as the argument. response.sendRedirect( );  Do this before any other JSP code in the page is run.