Handling FORM Data using Servlets

Slides:



Advertisements
Similar presentations
Servlets. Servlets are modules that extend Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry.
Advertisements

1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Multivalued parameters Some type of parameters may have more than one value. This is the case for the checkbox. What IDEs do you use? NetBeans Eclipse.
Server Side Programming Common Gateway Interface (CGI): Scripts generate Web pages or other files dynamically by processing form data and returning documents.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Servlets Stoney Jackson
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Servlets Replace Common Gateway Interface Scripts Extend Server Functionality Modules (software components) Like applets to browsers No GUI.
1 Servlets and HTML Form Data Parts of this presentation was provided by Vijayan Sugumaran Department of DIS Oakland University Rochester,
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
A Servlet’s Job Read explicit data sent by client (form data) Read implicit data sent by client (request headers) Generate the results Send the explicit.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Slides © Marty Hall, book © Sun Microsystems Press 1 Handling the Client Request: Form Data Core Servlets & JSP book:
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
Introduction To HTML Dr. Magdi AMER. HTML elements.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
Java Servlets References: Karen Anewalt, Mary Washington College.
Programming with Java Lecture 6 Elements of a Java Servlet
LECTURE 8 (ETCS-308) Subject teacher : Ms. Gunjan Beniwal
Client-Side Internet and Web Programming
How to Write Web Forms By Mimi Opkins.
Introduction to HTML Forms and Servlets
JDBC & Servlet CSE 4504/6504 Lab.
CS3220 Web and Internet Programming HTML Tables and Forms
Forms Web Design Ms. Olifer.
FORMS IN HTML.
Servlets Hits Counter 20-Jul-18.
FORMS Explained By: Sarbjit Kaur.
Web Design and Development
Session Tracking in Servlets
Getting User Input with Forms
HTML/XHTML Forms 18-Sep-18.
النماذج عند الانتهاء من هذا الدرس ستكون قادرا على:
Designing Forms Lesson 10.
1.5 FORMS.
HTML: Basic Tags & Form Tags
Creating Form Elements
Creating Form Elements
SERVLETS AND JDBC.
Servlets.
Servlets and Java Server Pages
Forms Data Entry and Capture
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Principles of Web Design 5th Edition
Web Search Interfaces.
Web Search Interfaces by Ray Mooney
Servlets.
Parameters passed by client
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
HTML Forms 18-Apr-19.
Java Servlets Servlet Overview Servlets and HTML Forms Servlet Basics
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
Parameters passed by client
Directories and DDs 25-Apr-19.
Lesson 6: Web Forms.
Basic servlet structure
Directories and DDs 21-Jul-19.
Servlets: Servlet / Web Browser Communication I
Directories and DDs 14-Sep-19.
HTML: Basic Tags & Form Tags
Presentation transcript:

Handling FORM Data using Servlets

HTML Forms An interface controls to collect data from the user and transmit it to server.

Element in Forms TEXT CONTROLS: PASSWORD FIELDS: TEXT AREAS: Checkbox <INPUT TYPE="TEXT" NAME="NAME" VALUE="INIT"> PASSWORD FIELDS: <INPUT TYPE="PASSWORD" NAME="PASSWORD"> TEXT AREAS: <TEXTAREA NAME="RESUME" ROWS=5 COLS=30>INPUT YOUR RESUME HERE </TEXTAREA> Checkbox <input type="checkbox" name="checkbox" checked> <input type="checkbox" name="checkbox"> Radio Button <input type="radio" name="radio" checked> <input type="radio" name="radio">

Cont. List Multilist <select name="list"> <option value="Item 1">Item 1</option> <option value="Item 2">Item 2</option> <option value="Item 3">Item 3</option> </select> Multilist <select name="multilist" size="3" multiple>

Cont. Submit Button Reset Button Image Button File <input type="submit" name="submit" value="Submit"> Reset Button <input type="reset" name="reset" value="Reset Fields"> Image Button <input type="image" name="image" src="go.gif"> File <input type="file" name="file">

HttpServletRequest - Methods Enumeration getParameterNames() an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters java.lang.String[] getParameterValues (java.lang.String name) Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. java.lang.String getParameter (java.lang.String name) Returns the value of a request parameter as a String, or null if the parameter does not exist.

Example <html> <body> <form action="CheckBox" method="POST" target="_blank"> <input type="checkbox" name="maths" checked="checked" /> Maths <input type="checkbox" name="physics" /> Physics <input type="checkbox" name="chemistry" checked="checked" /> Chemistry <input type="submit" value="Select Subject" /> </form> </body> </html>

Servlet CODE –Using getParameter import java. io. ; import javax Servlet CODE –Using getParameter import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class CheckBox extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("<html>\n" + "<head><title>" + title + "</title></head>\n" + "<body >\n" + "<ul>\n" + " <li><b>Maths Flag : </b>: " + request.getParameter("maths") + "\n" + " <li><b>Physics Flag: </b>: " + request.getParameter("physics") + "\n" + " <li><b>Chemistry Flag: </b>: " + request.getParameter("chemistry") + "\n" + "</ul>\n" + "</body></html>"); }

Servlet Code -Using getParameterValues import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class CheckBox extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); Enumeration paramNames = request.getParameterNames(); while(paramNames.hasMoreElements()) { String paramName = (String)paramNames.nextElement(); out.print("<tr><td>" + paramName + "</td>\n<td>"); String[] paramValues = request.getParameterValues(paramName); if (paramValues.length == 1) { String paramValue = paramValues[0]; if (paramValue.length() == 0) out.println("<i>No Value</i>"); else out.println(paramValue); } else { out.println("<ul>"); for(int i=0; i < paramValues.length; i++) { out.println("<li>" + paramValues[i]); } out.println("</ul>"); } } out.println("</tr>\n</table>\n</body></html>"); }

Using getparameternames http://way2java.com/servlets/servlet-getparameternames-example/

DEMO