Session 10. Form Dataset. Lecture Objectives

Similar documents
Session 9. Introduction to Servlets. Lecture Objectives

Session 20 Data Sharing Session 20 Data Sharing & Cookies

JAVA SERVLET. Server-side Programming PROGRAMMING

CREATE A SERVLET PROGRAM TO DISPLAY THE STUDENTS MARKS. To create a servlet program to display the students marks

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Lab session Google Application Engine - GAE. Navid Nikaein

CIS 3952 [Part 2] Java Servlets and JSP tutorial

To create a view for students, staffs and courses in your departments using servlet/jsp.

Session 8. Introduction to Servlets. Semester Project

CE212 Web Application Programming Part 3

Spring 2014 Interim. HTML forms

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres

Servlets by Example. Joe Howse 7 June 2011

Session 11. Calling Servlets from Ajax. Lecture Objectives. Understand servlet response formats

Develop an Enterprise Java Bean for Banking Operations

Stateless -Session Bean

HTML Forms. By Jaroslav Mohapl

Handout 31 Web Design & Development

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

Introduction to Servlets. After which you will doget it

Java4570: Session Tracking using Cookies *

J2ME With Database Connection Program

The Hypertext Markup Language (HTML) Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

AJP. CHAPTER 5: SERVLET -20 marks

Web based Applications, Tomcat and Servlets - Lab 3 -

HTML Tables and Forms. Outline. Review. Review. Example Demo/ Walkthrough. CS 418/518 Web Programming Spring Tables to Display Data"

Principles and Techniques of DBMS 6 JSP & Servlet

JavaServer Pages (JSP)

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?

Introduction. This course Software Architecture with Java will discuss the following topics:

Servlet Basics. Agenda

ServletConfig Interface

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

Using Java servlets to generate dynamic WAP content

Web Programming. Based on Notes by D. Hollinger Also Java Network Programming and Distributed Computing, Chs.. 9,10 Also Online Java Tutorial, Sun.

Forms, CGI. Objectives

ICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.

INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M 1.B HTML FORM CREATION - 2 M

WHITE LABELING IN PROGRESS ROLLBASE PRIVATE CLOUD

Construction d Applications Réparties / Master MIAGE

Advanced Internet Technology Lab # 5 Handling Client Requests

Chapter 1 FORMS. SYS-ED/ Computer Education Techniques, Inc.

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

NETB 329 Lecture 13 Python CGI Programming

1 Form Basics CSC309

Component Based Software Engineering

Summary 4/5. (contains info about the html)

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR

JAVA SERVLET. Server-side Programming INTRODUCTION

Database Application Development

HTTP status codes. Setting status of an HTTPServletResponse

JdbcResultSet.java. import java.sql.*;

Servlet. Web Server. Servlets are modules of Java code that run in web server. Internet Explorer. Servlet. Fire Fox. Servlet.

Penetration: from application down to OS

Unit-4: Servlet Sessions:

Backend. (Very) Simple server examples

HTML: Fragments, Frames, and Forms. Overview

CSE 154 LECTURE 8: FORMS

CS 112 Introduction to Programming

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM Advanced Internet Technology Lab.

Outline of Lecture 5. Course Content. Objectives of Lecture 6 CGI and HTML Forms

Advanced Internet Technology Lab # 4 Servlets

Server-Side Web Programming: Python (Part 1) Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

HTML and JavaScript: Forms and Validation

Université Antonine - Baabda

MTAT Enterprise System Integration

Java Server Pages JSP

D B M G. Introduction to databases. Web programming: the HTML language. Web programming. The HTML Politecnico di Torino 1

Creating Web Pages Using HTML

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

Java TM. JavaServer Faces. Jaroslav Porubän 2008

Selected Sections of Applied Informatics Lab 3

Forms, CGI. HTML forms. Form example. Form example...

USQ/CSC2406 Web Publishing

Handling Cookies. Agenda

Chapter 9: Application Design and Development

Kamnoetvidya Science Academy. Object Oriented Programming using Java. Ferdin Joe John Joseph. Java Session

Servlet 5.1 JDBC 5.2 JDBC

Getting Data from the Web with R

COMP9321 Web Application Engineering

Demonstration of Servlet, JSP with Tomcat, JavaDB in NetBeans

Forms, CGI. Cristian Bogdan 2D2052 / 2D1335 F5 1

Servlets and JSP (Java Server Pages)

Database Applications Recitation 6. Project 3: CMUQFlix CMUQ s Movies Recommendation System

servlets and Java JSP murach s (Chapter 4) TRAINING & REFERENCE Mike Murach & Associates Andrea Steelman Joel Murach

SSC - Web applications and development Introduction and Java Servlet (I)

Testing Web Database Applications. Yuetang Deng Phyllis Frankl Jiong Wang

PYTHON CGI PROGRAMMING

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Session 11. Ajax. Reading & Reference

3. The pool should be added now. You can start Weblogic server and see if there s any error message.

Internet Technologies 5-Dynamic Web. F. Ricci 2010/2011

Introduction to Java Servlets. SWE 432 Design and Implementation of Software for the Web

&' () - #-& -#-!& 2 - % (3" 3 !!! + #%!%,)& ! "# * +,

CSC309: Introduction to Web Programming. Lecture 8

Get the cookies from the service request: Cookie[] HttpServletRequest.getCookies() Add a cookie to the service response:

Scheme G Sample Question Paper Unit Test 2

First Simple Interactive JSP example

HTML 5 Tables and Forms

Transcription:

Session 10 Form Dataset Lecture Objectives Understand the relationship between HTML form elements and parameters that are passed to the servlet, particularly the form dataset 2 10/1/2018 1

Example Form Input to a Servlet <head> <title>who are you?</title> </head> <body> <form method="get" action= "http://localhost:8080/cse336-2017/helloyou.html"> <p>what is your name?</p> <input type="text" name="fullname" value="enter name" /> <br /> <input type="submit" /> </form> </body> </html> Entering a name in this component changes the value of this form parameter Input components are grouped by a form element HelloYou.html 3 HelloYou Servlet out.println(doctype); String name = request.getparameter("fullname"); out.println("<html>"); out.println("<head><title> Hello, " + name + "</title></head>"); out.println("<body>"); out.println("hello, " + name); out.println("</body></html>"); out.close(); Servlet reads value of form data set 4 10/1/2018 2

HTML Form Element A form element contains component elements that are used to collect information on a Web page Each component typically has a name and a value The collection of name/value pairs is referred to as the form data set Form values are initially set to the value in the html, but changed when the user enters data The entire form is associated with a URL that can obtain the data (usually after the submit button is pressed) 5 HTML control types: HTML Form Element Buttons Submit Check boxes Radio buttons Menus Text input (INPUT and TEXTAREA) Password File select Some form components can be Hidden controls multi-valued Object controls Users complete a form by modifying the form elements and then submitting to the server for servlet processing 6 10/1/2018 3

Drop-Down Component <select name="countryofres" id="countryresidence"> <option selected="selected" value="">select one</option> <option value="cn">china</option> <option value="fr">france</option> <option value="de">germany</option> <option value="ie">ireland</option> <option value="gb">united Kingdom</option> <option value="us">united States</option> </select> The value of the CountryOfRes form element is initially, but changes when the user selects a different menu item 7 Parameter name Vs. Parameter Value Consider the following country drop-down form <select name="countryofres" id="countryresidence"> <option selected="selected" value="">select one</option> <option value="cn">china</option> <option value="fr">france</option> <option value="de">germany</option> <option value="ie">ireland</option> <option value="gb">united Kingdom</option> <option value="us">united States</option> </select> Notice that the value attribute is not always the same as the text 8 contained in the value element 10/1/2018 4

Form Element Server Coordination A Form element specifies attributes for: The program that will handle the completed and submitted form (action attribute) A script program that evaluates prior to submission to the server - and that can prevent data from being submitted. (onsubmit attribute) The method by which the user data will be sent to the server (method attribute) GET form data set is appended to the URL with a? (used when form causes no side effects) POST form data set is included in the body of the form 9 Form Data Set GET method - Form data set is included in the URL query string (by the browser) www.mysite.com/path/program?first_name=kevin&last_name=knox Note the use of: = associates a value with a name & separates consecutive name/value pairs Form dataset POST method Form data set is encoded in a similar manner, but included in the http message body Post form data set is not immediately visible 10 10/1/2018 5

Form Elements A form element s name is given by the name attribute A form element has an initial value and a current value (both are strings) A form element is displayed in the browser according to the value of the type attribute Form submission - for the successful submissions, the form element s value is paired with its name all of these pairs are referred to as the form data set <input name ="ifirst_name" value="" type="text" /> Type attribute of the input tag is not required (default value is text ), but it is a good practice to do so 11 Radio Buttons Radio buttons only occur in groups (only one can be selected at a time) Radio button group is specified with a common name attribute <td><span class= asterisk">*</span> Do you need hotel reservations?<br />... Please make your hotel reservations through us.</td> <td> <input name="ihotel" value="yes" type="radio" /> Yes<br /> <input name="ihotel" value="no" type="radio checked= checked /> No </td> <td></td> You can optionally specify the default selected button or checkbox One radio button in the group should have checked= checked 12 10/1/2018 6

Example Display the Form dataset HelloFormDataset.html 13 FormDataset For GET requests, the form dataset is contained in the URL query string <form action="http://localhost:8080/cse336-2017/helloformdataset"> <input name="bgcolor" type="radio" value="red" checked="checked" />... </form> 14 10/1/2018 7

FormDataSet Servlet Fragment out.println("the form dataset for this request is "); out.print(request.getquerystring()); 15 Are We on Track? Download Track-Fall2018.html Modify the html so that the action attribute of the form refers to a servlet you will write Write a servlet that when called from the form will display the form parameter names Your solution might vary based on whether you ve checked a box or not 16 10/1/2018 8

Were We on Track? @WebServlet(name = "FormParameters", urlpatterns = {"/FormParameters"}) public class FormParameters extends HttpServlet { protected void processrequest(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html;charset=utf-8"); try (PrintWriter out = response.getwriter()) { out.println("<!doctype html>"); out.println("<html>");... out.println("<h1>developerworks parameters:</h1><ul> "); Enumeration e = request.getparameternames(); while (e.hasmoreelements()) { out.println("<li>" + e.nextelement() + "</li>"); } out.println("</ul>"); out.println("</body>"); out.println("</html>"); } }} 17 Have You Satisfied the Lecture Objectives? Understand the relationship between HTML form elements and parameters that are passed to the servlet, particularly the form dataset 18 10/1/2018 9