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.

Slides:



Advertisements
Similar presentations
JSP -exercises- Alessandro Marchetto Fondazione Bruno Kessler-IRST, Centro per la Ricerca Scientifica e Tecnologica.
Advertisements

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.
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.
Server-Side Scripting with Java Server Page, JSP.
JSP Java Server Pages Reference:
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
Multiple Tiers in Action
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
Contrast with JavaScript HTML Formsto invoke Java Server Pages Structure of Forms Query strings Java Server Pages Sent From Browser To Serverfor JSP.
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.
CSCI 6962: Server-side Design and Programming History and Background.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
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.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
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.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
Chapter 2 An Overview of Servlet and JSP Technology.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Jsp (Java Server Page) Is a server side program.
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 Java Server Faces Scoping and Session Handling.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
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 –
Chapter 11 Invoking Java Code with JSP Scripting Elements.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software.
Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
Server-Side Scripting with Java Server Page, JSP.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
1 Chapter 27 JavaServer Page. 2 Objectives F To know what is a JSP page is processed (§27.2). F To comprehend how a JSP page is processed (§27.3). F To.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Introduction To HTML Dr. Magdi AMER. HTML elements.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
JSP / Servlets and Beans
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Java Class and Servlet ISYS 350.
Handling Errors in Web Applications
Java Servlets By: Tejashri Udavant..
Scripted Page Web App Development (Java Server Pages)
AJAX and Java Servlet ISYS 350.
JSP Implicit Objects Implicit Objects in JSP are objects that are automatically available in JSP. request: The request object retrieves the values that.
Server-Side Scripting with Java Server Page, JSP
Server-Side Scripting with Java Server Page, JSP
AJAX and JSP ISYS 350.
Java Servlet ISYS 350.
J2EE Lecture 1:Servlet and JSP
AJAX and JSP ISYS 350.
Struts BY: Tejashri Udavant..
Presentation transcript:

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 was submitted from an HTML form Provide dynamic content such as the results of a database query. It is not a web page and cannot be opened by itself. A servlet is called by a HTML form’s action attribute:

Adding a Servlet Servlet is a class with a “java” extension: – Ex: FVServlet.java It must belong to a package: – Add a new package – Then add a new servelet – Ex:ServletPackage FVServlet.java

Servlet’s processRequest Method This method use the same request and response objects as JSP. For example, it uses the request.getParameter method to read the data submitted with http request: – myPV=request.getParameter("PV"); It uses the out.println statement to send HTML code to browser: out.println(" ");

Example: Future Value Calculator: Requesting FVServlet servlet Enter present value: Select interest rate: 4% 5% 6% 7% 8% Select year: 10-year 15-year 30-year

FVServlet protected void processRequest(HttpServletRequest request, HttpServletResponse response) String myPV, myRate, myYear,qString; 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); Note: Copy/paste the code between: out.println(" "); and out.println(" ");

Servlet: depTableServlet to create straight line depreciation table Straight Line Depreciation Table Enter Property Value: Enter Property Life:

String strValue, strLife; strValue=request.getParameter("pValue"); strLife=request.getParameter("pLife"); double value, life, depreciation,totalDepreciation=0; value=Double.parseDouble(strValue); life=Double.parseDouble(strLife); NumberFormat nf = NumberFormat.getCurrencyInstance(); out.println("Straight Line Depreciation Table" + " "); out.println("Property Value: "); out.println("Property Life: "); depreciation=value/life; totalDepreciation=depreciation; out.println( " "); out.println(" Year Value at BeginYr "); out.println(" Dep During Yr Total to EndOfYr "); out.println(" "); for (int count = 1; count <= life; count++) { out.write(" "); out.write(" " + count + " "); out.write(" " + nf.format(value) + " "); out.write(" " + nf.format(depreciation) + " "); out.write(" " + nf.format(totalDepreciation) + " "); value -= depreciation; totalDepreciation+=depreciation; }