Directories and DDs 14-Sep-19.

Slides:



Advertisements
Similar presentations
14-May-15 An Example Servlet Putting it all together.
Advertisements

COMP 321 Week 8. Overview MVC Example Servlet Lifecycle Servlet Mechanics MVC Lab 5-2 Solution Lab 8-1 Introduction.
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
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
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
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.
27-Jun-15 Directories and DDs. 2 Web apps A web application is basically a web site that: “Knows who you are”--it doesn’t just give you static pages,
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
14-Jul-15 Tomcat. 2 The Apache Jakarta Project The Apache Jakarta Project “creates and maintains open source solutions on the Java platform for distribution.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Java Servlets and JSP.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Functionality of a web server What does the web server do? Let a user request a resource Find the resource Return something to the user The resource can.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
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.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Java Servlets and Java Server Pages Norman White Stern School of Business.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
Java Servlets and Java Server Pages
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Introduction To HTML Dr. Magdi AMER. HTML elements.
 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,
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
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.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Introduction to Servlets
APACHE TOMCAT WEB SERVER
CS3220 Web and Internet Programming Introduction to Java Servlets
Building Web Apps with Servlets
Java Servlets By: Tejashri Udavant..
Net-centric Computing
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Servlets Hits Counter 20-Jul-18.
Session Tracking in Servlets
Introduction to Struts
CHAPTER 10 Servlet Programming
Jagdish Gangolly State University of New York at Albany
Servlets and Java Server Pages
Representation and Management of Data on the Web
COP 4610L: Applications in the Enterprise Spring 2005
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
Servlets.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Introduction to Java Servlets
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Directories and DDs 25-Apr-19.
Directories and DDs 21-Jul-19.
Presentation transcript:

Directories and DDs 14-Sep-19

Web apps A web application is basically a web site that: “Knows who you are”--it doesn’t just give you static pages, it interacts with you Can permanently change data (such as in a database) A web application can consist of multiple pieces Static web pages (possibly containing forms) Servlets JSP Tomcat organizes all these parts into a single directory structure for each web application ...but you have to help with the organization

Directories To create servlets, you really should have two directory structures: A development directory, in which you can write and partially debug your code A deployment directory, in which you put “live” code Tomcat requires a particular set of directories for your web application It is extremely picky about having everything in the right place! Since your web application must typically co-exist with other web applications, you should use packages to avoid name conflicts This further complicates the Tomcat directory structure

Packages A package statement in Java must be the very first line of code in the file Example: package com.example.model; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class MyServlet extends HttpServlet { ... } This implies that This program is in a file named MyServlet.java, which is in a directory named model, which is in a directory named example, which is in a directory named com That is, the file is something/com/example/model/MyServlet.java

Separation of concerns Business logic is the part of your application that does the actual computational work It is a good idea to separate the business logic of any application from the part that communicates with the outside world This allows you to use the same business logic as an applet, a servlet, an application, or an API used by another program In the following examples we will assume: The business logic is in the package com.example.model The servlet logic is in the package com.example.web

Tomcat directory structure jakarta-tomcat-5.5.9/ -- your Tomcat home directory (whatever it’s named) webapps/ myApplicationDirectory/ -- your name for your application directory myWebForm.html -- static HTML pages go in your application directory myJspResult.jsp -- JSP pages also go in your application directory WEB-INF/ -- must have this directory, named exactly like this web.xml -- this is the deployment descriptor, it must have this name lib/ -- you can use this optional directory for external .jar files classes/ -- must have this directory, named exactly like this com/ -- The com.example.model package directory example/ web/ myServlet.class --in package com.example.web; model/ myModel.class -- in package com.example.model;

My files myWebForm.html com/example/web/myServlet.class This is the web page with a form that sends data to the servlet com/example/web/myServlet.class This is the servlet I intend to use; it will use the myModel class, but to do this it needs an import statement: import com.example.model.myModel; com/example/model/myModel.class This does the “business logic” it is good form to keep it separate myJspPage.jsp The (optional) JSP page to create the HTML output (could be done directly by myServlet) web.xml A file required by Tomcat to tell it what class to start with and how to refer to that class

myWebForm.html <html> ... <body> <form method="POST" action="NameSeenByUser.do"> ...various form elements... </form> </body> </html>

How Tomcat finds the servlet Tomcat reads XML files that tell it about the servlets Each web application must have a Deployment Descriptor (DD) file, WEB-INF/web.xml file The root element of the DD file is web-app This element has a bunch of “boilerplate” attributes You don’t have to know what any of it means The rest of the XML file gives names for the servlet, provides parameters, etc. We’ll cover only the most essential parts

Three names Every servlet has up to three names: The “real” name, given to it by the programmer An “internal” name, used only within the web.xml file The name that the user (client) knows it by The <servlet> element associates the fully-qualified class name with the internal name The <servlet-mapping> element associates the internal name with the name known to the client Apparently, the reason for all this is to increase security by hiding the real name from the user

web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <servlet> <servlet-name>Some internal name</servlet-name> <servlet-class>com.example.web.MyServlet</servlet-class> </servlet> <servlet-mapping> <url-pattern>/NameSeenByUser.do</url-pattern> </servlet-mapping> </web-app>

The Servlet public class MyServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String value = request.getParameter("name"); out.println("<html><body>I got: " + name + " = " + value + "</body></html>"); }

Flow The user submits an HTML form Tomcat finds the servlet based on the URL and the deployment descriptor (web.xml) and passes the request to the servlet The servlet computes a response Either: The servlet writes an HTML page containing the response Or: The servlet forwards the response to the JSP The JSP embeds the response in an HTML page Tomcat returns the HTML page to the user

The End