Servlets Enterprise Systems Programming. Servlets  Servlets: server-side Java programs that enable dynamic processing of web-based requests  Web-based.

Slides:



Advertisements
Similar presentations
AppViewXS Installation Infrastructure Overview Web Server Application Server.
Advertisements

Architecture of the COREP-XBRL mapper Java based web application Uses only open source packages of Java + struts.jar for the GUI + poi.jar for the reading.
JSP and web applications
WEB SERVICES. FIRST AND FOREMOST - LINKS Tomcat AXIS2 -
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages Java Server Pages - Xue Bai.
Apache Struts Technology
Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
Configuring web servers and web applications 1. 2 Server configuration vs. application configuration A web server may run several web application Server.
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
Multiple Tiers in Action
Apache Tomcat Server Typical html Request/Response cycle
MC365 Application Servers: Java Server Pages (JSP’s) and Session Management.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
Java Server Team 8. Overview What is a Java Server? History Architecture Advantages Disadvantages Current Technologies Conclusion.
Building and Deploying a Simple Web Application. Tomcat and JSP Tomcat is an application server, commonly used to host JSP applications Applications are.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
Julien Thibault / Phil Brewster / Kristina Doing-Harris
Java Servlets and JSP.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Intro to Servlets Lec 26. Web-Based Enterprise Applications in Java Figure shows a simplified view of one application and its layers.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Applets & Servlets.
SSC2: Web Services. Web Services Web Services offer interoperability using the web Web Services provide information on the operations they can perform.
Christopher M. Pascucci.NET Programming: Basic ASPX Scripting & HTML Embedment.
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
Matrix Mapping Tool Sam Gross Internship at Virtual Technology Corporation.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Topic Java EE installation (Eclipse, glassfish, etc.) Eclipse configuration for EE Creating a Java Web Dynamic Project Creating your first servlet.
Java Portals and Portlets Submitted By: Rashi Chopra CIS 764 Fall 2007 Rashi Chopra.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
Spring Framework. About spring Spring is the most popular application development framework for enterprise Java. Millions of developers around the world.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
VERI is an interface that provides a Web based front end to the access the datasets generated by the MVED. The goal is to Provide open access to the Don.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
Server Side Scripting Perl, Python, Java Servlets  write complete programs in (Perl, Python, Java) to process HTTP requests and generate a complete HTTP.
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
 2003 Prentice Hall, Inc. All rights reserved Deploying a Web Application ( may include.war )
 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,
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Labs: Create, deploy and test a simple web service
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Net-centric Computing
Course Outcomes of Advanced Java Programming AJP (17625, C603)
By Dr. Kodge Bheemashankar G
Unit 6-Chapter 2 Struts.
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
Introduction to Struts
Java Servlet Ziad A. Al-Sharif.
A Match Made In (Ethereal) Heaven
Objectives In this lesson you will learn about: Need for servlets
COP 4610L: Applications in the Enterprise Spring 2005
COP 4610L: Applications in the Enterprise Spring 2005
Java Servlets and JSP.
Directories and DDs 25-Apr-19.
Directories and DDs 21-Jul-19.
Jungkee (Jake) Kim TMD and XML Jungkee (Jake) Kim
Directories and DDs 14-Sep-19.
Presentation transcript:

Servlets Enterprise Systems Programming

Servlets  Servlets: server-side Java programs that enable dynamic processing of web-based requests  Web-based requests are coursed through html forms  Servlets process these requests and typically generates html-formatted responses to these requests  Servlets resides on a web server that supports servlet functionality e.g., Apache Tomcat These servers are also called web containers or servlet containers

Web application structure  A web application consists of several files placed inside a context root folder  Structure: html file(s) referring to servlet pages WEB-INF  web.xml  classes   Java servlet class file(s)

Web-application example  Simple Example: mywebapp welcomeform.html WEB-INF  web.xml  classes  servlets  WelcomeServlet.class

Web-application example  Simple Example: mywebapp welcomeform.html WEB-INF  web.xml  classes  servlets  WelcomeServlet.class refers to servlet page (html source need not reside inside mywebapp) contains mapping(s) of URL to actual servlet code servlet code could be an elaborate package folder hierarchy

Web-application example  Simple Example: mywebapp welcomeform.html WEB-INF  web.xml  classes  servlets  WelcomeServlet.class … <form action="/mywebapp/welcome" … maps "/welcome" to servlets.WelcomeServlet

web.xml contents  web.xml: deployment descriptor  Most important portions: Establishing aliases: associate servlet name to actual servlet code Mapping: associates a URL to a servlet name

web.xml example welcome servlets.WelcomeServlet welcome /welcome

HTML forms  HTML form: section of a webpage that contains input elements (e.g., text boxes)  Often contains a submit element (a button) that enables submission of the form contents to a web server  Submission is associated with an action (the URL of the page that processes the form)

HTML form example TYPE IN SOME TEXT

Form methods  Two types of form submission methods  GET: form data is appended to the URL (data separated from the action URL by question mark) Use this for query-type actions or indempotent actions  POST: form data is “passed” or included as a message to the web-server Use this for actions with side-effects

HttpServlet class  Class that servlets extend  Expect to override at least one of the following methods: protected doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException protected doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException  Read form data through the request parameter, generate output/resulting webpage through the response parameter

HttpServletRequest  Most important method: getParameter()  Given the input parameter name (indicated in the HTML form), returns a string that represents the associated form data  May need to use Java conversion features (such as Integer.parseInt()) to convert to the appropriate type for processing  Examples: String name = request.getParameter( "firstname" ); int year = Integer.parseInt( request.getParameter( "year" ) );

HttpServletResponse  Used to facilitate result of processing a form  “generates” html content  Invoke the getWriter() method to get a PrintWriter handle, then issue print, println methods on that handle  Invoke getContentType(“text/html”) to specify that you are generating html content  Example: response.setContentType( "text/html" ); PrintWriter out = response.getWriter(); out.println( " Welcome " );

Complete doGet() example protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { String name = request.getParameter( "firstname" ); int favoriteNumber = name.length(); response.setContentType( "text/html" ); PrintWriter out = response.getWriter(); out.println( " Welcome " + name + " " ); out.println( "Your favorite number is “ + favoriteNumber ); out.close(); }

Connecting to a database  Combine JDBC concepts and servlets  Better to separate code that connect to the database Tip: have a collection of methods that carry out query or update methods on the database and then invoke these methods from the servlet  Database code could be in a separate package or be part of the package containing servlet code

doGet() with database access protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { String name = request.getParameter( "firstname" ); String mobileNumber; try { mobileNumber = DBAccess.getNum( name ); } catch( Exception e ) { mobileeNumber = "no mobile number"; } response.setContentType( "text/html" ); PrintWriter out = response.getWriter(); out.println( " Welcome " + name + " " ); out.println( "Your MOBILE number is " + mobileeNumber ); out.close();  } getNum() is a method of DBAccess.java and contains JDBC code

Summary  Servlets process form data through java Java programs that extend HttpServlet  Servlets are part of a web application web.xml indicates appropriate mappings  Other servlet features: redirection, sessions/cookies  Next: JSP (simplifies servlet coding)