Author: DoanNX Version 2.0/Time: 30’. The ways to solve it There are 2 main ways:  Client-side: Using JavaScript (now one very good option is JQuery).

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Apache Struts Technology
MVC Frameworks Alternatives to coding the MVC pattern.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
Struts1 Apache Struts Dr Jim Briggs. Struts2 What is Struts? Struts is an open source framework for building Java web applications Supports MVC/Model.
DT211/3 Internet Application Development JSP: Processing User input.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
DT211/3 Internet Application Development
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Apache Struts Technology A MVC Framework for Java Web Applications.
Tutorial 11: Connecting to External Data
Microsoft Office Word 2013 Expert Microsoft Office Word 2013 Expert Courseware # 3251 Lesson 4: Working with Forms.
JavaScript Demo Presented by … Jaisingh Sumit jain Sudhindra Taran Deep arora.
. If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example,
UNIT-V The MVC architecture and Struts Framework.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Microsoft Windows 2003 Server. Client/Server Environment Many client computers connect to a server.
1 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and Custom Forms.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
JavaScript Form Validation
JavaScript & jQuery the missing manual Chapter 11
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
.NET Validation Controls MacDonald Ch. 8 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Introduction to MVC and the Jakarta Struts Framework By Gyanendra Dwivedi Software Consultant.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Standalone Java Application vs. Java Web Application
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Lesson 2.  To help ensure accurate data, rules that check entries against specified values can be applied to a field. A validation rule is applied to.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Tutorial 10 Programming with JavaScript
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
How to Build a Struts Application with JBuilder 9.
Introduction to Exception Handling and Defensive Programming.
Microsoft FrontPage 2003 Illustrated Complete Creating a Form.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
Struts An Open-source Architecture for Web Applications Facilitator: Tripti Shukla.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
11 Copyright © 2004, Oracle. All rights reserved. Customizing Actions.
Struts Framework Day-2 Ashok Chakravarti. DataSource Usage Sample Struts-config.xml …
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Quick Test Professional 9.2. Testing Process Preparing to Record Recording Enhancing a Test Debugging Running the Test and Analyzing the Results Reporting.
DT228/3 Web Development JSP: Actions elements and JSTL.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Chapter 14 Using JavaBeans Components in JSP Documents.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Getting Started in Access 1 Using an existing Database Database Window Table Design View Parts of a Table Views in Access Navigating in Access Entering.
Apache Struts Technology A MVC Framework for Java Web Applications.
//liveVirtualacademy2011/ What’s New for ASP.NET 4.5 and Web Development in Visual Studio 11 Developer Preview Γιώργος Καπνιάς MVP, MCT, MCDP, MCDBA, MCTS,
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Sixth Edition
Chapter 3: Using Methods, Classes, and Objects
Presentation transcript:

Author: DoanNX Version 2.0/Time: 30’

The ways to solve it There are 2 main ways:  Client-side: Using JavaScript (now one very good option is JQuery).  Server-side: Manually. Automatically (using Struts Validator Framework).

Client-side Validation  Using JavaScript. Do it yourself.

Server-side Validation Manually  Manually.  Automatically (using Struts Validator Framework).

Server-side Validation Manually  Execute manually: Performing in the Action classes: ○ Most powerful, we can access to BL as well as DB. ○ It requires repetition in multiple Actions. ○ We must map conditions back to the input page. Do validation in the form bean (ActionForm): ○ In individual setter methods. ○ Using the validate methods: It doesn’t require repetition in multiple Actions. It will automatically redisplay input page.

Server-side Validation Manually Fig 1. Flow of Control when performing validation in the Action classes.

Server-side Validation Manually  Performing in the Action classes: Start normally: ○ Cast ActionForm to specific type. ○ Call getter methods to retrieve field values. For each missing or invalid value: ○ Add an error message to a bean. ○ Use mapping.findForward to return error code. Use struts-config.xml to map the error code back to the input form. Use bean:write to output error messages in input form.

Fig 2. Flow of Control when performing validation in the ActionForm classes. Server-side Validation Manually

 Do validation in the form bean (ActionForm): Using validate() method of ActionForm class: ○ If no errors, return null or an empty ActionErrors object. ○ For each error, add ActionMessage entries to ActionErrors: ActionErrors.add() takes a name and an ActionMessage object. ActionMessage constructor takes key: -Key corresponds to entry in a property file. -Or, supply extra value of false to supply error message directly. ○ If you return a non-empty ActionErrors object, the system will automatically forward user to the input form. Server-side Validation Manually

 validate() method: Server-side Validation Manually public ActionErrors validate (ActionMapping map, HttpServletRequest req) { ActionErrors errors = new ActionErrors(); if (isSomeProblem( getSomeProperty())) { // add() method errors.add("someName“, new ActionMessage("some.key")); // add() method errors.add("someOtherName“, new ActionMessage("actual message", false)); }... return(errors); }

 Do validation in the form bean (ActionForm) (cont): Specifying input page in struts-config.xml: Server-side Validation Manually <action path="/somePath/someActionName" type="somePackage.SomeClass" name="someFormBean" scope="request" input="/somePath/original-form.jsp“ />

 Do validation in the form bean (ActionForm) (cont): Create a property file with error messages: ○ Property names should match keys used in ActionMessage object. ○ We also define how multiple error messages are output. ○ Use struts-config.xml file to declare properties file. Server-side Validation Manually

 Do validation in the form bean (ActionForm) (cont): The content of properties file: Server-side Validation Manually # -- Standard errors -- errors.header = errors.prefix = errors.suffix = errors.footer = # -- Custom validation messages -- some.key = Some Message some.other.key = Some Other Message

 Do validation in the form bean (ActionForm) (cont): Using parameterized error messages: ○ Benefits: Error messages reflect runtime values. Less repetition of error messages. More meaningful error messages for situations other than missing-data. Server-side Validation Manually

Using parameterized error messages (cont): ○ Properties file: Insert placeholders for values with {0}, {1}, etc. Ex: value.required = {0} is required. ○ In ActionForm class: Add extra arguments to ActionMessage constructor: -One argument for each placeholder. -Up to four separate arguments allowed (if more arguments needed, supply an array). Perform more complex validation (types of arguments, relationship among values, etc.) Server-side Validation Manually

Server-side Validation Automatically  Handles many common cases; includes JavaScript.  You can combine approaches in the same application.

 Manual vs. Automatic validation: choose which? Server-side Validation Automatically

 Manual validation: Most flexible. Has full access to bean and to business logic and database. But Repeats same logic many times. Tedious. Embedded in Java code: ○ Which violates Struts strategy of having as much as possible in editable XML files. Server-side Validation Automatically

 Automatic validation: Consolidates validation code. Lets you use standard validation rules. Runs on server; can optionally also run on client. Described by XML files. But… Server-side Validation Automatically

 Another battle: Client-Side vs. Server-Side validation: who win? Server-side Validation Automatically

 Client-side validation: JavaScript code verifies format of fields. Dialog box warns users of illegal values. Submission blocked if invalid. Fast. But Can be deliberately or accidentally by passed. Can not do validation that requires much application logic. Server-side Validation Automatically

 Server-side validation: Java code on server verifies format of fields. Form is redisplayed (with warnings) if illegal values. You must do this regardless of whether or not you do client-side validation! Server-side Validation Automatically

 Using Struts Validator Framework: Configure struts-config.xml file: ○ List the address of the input form. ○ List the properties file (resource bundle). Refers to WEB-INF/classes/MessageResources.properties file. ○ Turn on the automatic validator. Don't enter by hand: uncomment the auto declaration. <set-property property="pathnames” value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml“ /> Server-side Validation Automatically

 Using Struts Validator Framework (cont): Edit the properties file: ○ Put errors.footer, errors.header for html:errors like as the previous slides. Example: errors.header= errors.prefix= errors.suffix= errors.footer= Server-side Validation Automatically

Edit the properties file (cont): ○ Edit standard validator messages (errors.invalid, etc). errors.invalid={0} is invalid. errors.maxlength={0} cannot be greater than {1} characters. ○ Create names to replace {0}, {1} in standard messages. inputForm.firstName=First name inputForm.lastName=Last name inputForm.zipCode=5-digit ZIP Code Server-side Validation Automatically

 Using Struts Validator Framework (cont): Put validation rules in validation.xml: ○ For each field, specify one or more validation rules. required, mask, , intRange, maxLength, etc. ○ Find the name of the corresponding error message. Usually errors.ruleName, but given in validator-rules.xml. ○ Look in properties file to see how many args needed. errors.invalid={0} is invalid. errors.maxlength={0} cannot be greater than {1} characters. ○ Supply arg0... argN as necessary. Server-side Validation Automatically

Put validation rules in validation.xml (cont): ○ and : main enclosing elements. ○ : matches form-bean name from struts-config.xml. ○ <field property="firstName“: matches HTML form parameter (ie, bean property) name. ○ depends="required">: matches name of predefined validator rule: required: must be non-empty. mask: must match a given regular expression. must be an address. creditCard: must be a legal credit card number (use for testing). ○ : replaces {0} in error message from properties file. Server-side Validation Automatically

 Using Struts Validator Framework (cont): Have your form bean extend ValidatorForm base class, not ActionForm class directly. import org.apache.struts.validator.*; public class OrderFormBean extends ValidatorForm { … } Server-side Validation Automatically

 Using Struts Validator Framework (cont): Put in input page. ○ Edit properties file to customize form of error message. Enable JavaScript validation (optional). ○ Add anywhere. ○ Add onsubmit="return validateBeanName(this);" to html:form. Server-side Validation Automatically

Reference document   