Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.

Similar presentations


Presentation on theme: "1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW."— Presentation transcript:

1 1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW

2 Objectives  Web Client – Server Model  Evolution of Servlets  Web Application  Web Application Development Process  Servlet API  Workshops 2

3 Client – Server Model 3 Advantages of Web Application Easier access to information Lower maintenance and deployment costs Platform independency Wider visibility

4 Architecture of Web Applications 4 N – tiers Architecture

5 5 How Web Server works ? Translate 2. Server name – Microsoft.com 3. File name – index.htm 1. Protocol – HTTP www.Mi…IP address Connect Browser send a GET request Server response as HTML format

6 6 Web server …? http://servername/HelloWorld.html File system contains HelloWorld.html

7 Communication/ Protocols Http Protocol Request Message structures Response Message structures

8 Request Objects 8  Request Parameters  Request Methods

9 Limitation of Web Servers 9  Not feasible to maintain static content from the customer’s end  Can not be managed the dynamic Web contain from client  Overloading errors  Unavailability due to maintenance  Heavy traffic  High maintenance costs  Virus or worms attacks

10 10 Architechture : Web Application Collect information Send Request to Web ServerExecute Server Script Response result to browser

11 11 Server Side Script  Common Gateway Interface (CGI).  ISAPI  Server-side JavaScript (SSJS).  Personal Home Page (PHP).  Java Servlet  Active Server Page (ASP)  Java Server Page (JSP).  Ruby on Rail  ASP.net  …………………………………..

12 CGI 12 Disadvantages Reduced efficiency Reloading Perl interpreter No Session #include void main() { printf(“ \n”); printf(“ My CGI program \n”); printf(“ Hello \n”); printf(“ \n”); }

13 Servlets 13

14 Web Application 14  Concepts  Registered into WWW  Accessible from a public server  Comprises servlets, JSPs, images, HTML, JavaBeans, applets, and Java classes  Portability  Store in WAR files to deploy on the Web server

15 Web Application Directory Structure 15

16 Web Deployment Descriptor – web.xml servlet name [package.]classname servlet name /context Path/root 30 default page to show Place in WEB-INF folder

17 Example HelloServlet demo.HelloServlet HelloServlet /Welcome Welcome index.jsp Alias Name

18 Web Application Development Process in NetBeans 18  Step 1: Creating a new project  Step 2: Specifying Name and Location for the Project  Step 3: Creating the new Web files.  Step 4: Specifying the Name of the Servlets  Step 5: Writing the code for Servlet & Compile  Step 6: Package Servlet into WAR file  Step 7: Deploying in a Web Container  Step 8: Executing the Servlet

19 Creating a new project  Click menu File  Click the “New Project” Items

20 Creating the new Web Project  Click Web categories  Click the “Web Application” Projects  Click Next button

21 Specifying Name and Location for the Project Fill your project name Browser your location where store the project  Click Finish button

22 Choose Server 22 Choose WebServer and Context Path, click “Next”, “Finish”

23 Web Application Directory Structure in Netbeans Project name Interactive Web Directory Web Deployment descriptor Configuration directory related define for Web App Source java class required for Web App Lib directory required for Web App

24 Create Servlet 24

25 Named for Servlet 25 Name Must have Package name Click :”Next”  “Finish”

26 Writing the code for Servlet & Compile  Modify the processRequest method in servlet class. Ex: protected void processRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType ("text/html;charset=UTF-8"); PrintWriter out = response.getWriter (); out.println(" "); out.println(" Hello Servlet "); out.println(" "); out.println(" Welcome to Servlet course "); out.println(" "); out.close (); }

27 Writing the code for Servlet & Compile (cont)

28 Package Servlet into WAR file  Package War file with command prompt  jar –cvf fileName.war directoryOrFile (using blank to separate)  Ex: jar –cvf HelloServlet.war *.jsp WEB-INF/*  You can manual deploy this application : copy.war file to folder TOMCAT_HOME/webapps

29 Executing the Servlet

30 GenericServlet Class 30

31 HTTPServlet Class 31

32 Workshop Activities 32 Building the first Servlet named HelloServlets to greet the user “Hello Servlets” in the Web browser. Notes: The NetBean runs the Servlet with the Tomcat Server version 6.0.24


Download ppt "1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW."

Similar presentations


Ads by Google