Java Server and Servlet
description
Transcript of Java Server and Servlet
![Page 1: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/1.jpg)
Java Server and Servlet
CS616 Team 9
Kim Doyle, Susan Kroha,
Arunima Palchowdhury, Wei Xu
![Page 2: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/2.jpg)
• History
• What is a Java Server/Servlet
• Architecture
• Pros and Cons
• Existing Java Servers
• Conclusion
Java Server and Servlet
![Page 3: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/3.jpg)
History
• Web has undergone rapid changes
• E-Commerce Transition from static to dynamic environment Birth of Common Gateway Interface (CGI)
• CGI languages include Perl C, C++ Visual Basic Script
![Page 4: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/4.jpg)
CGI Pros and Cons
Browser
HTTP
Web Server
CGI bin
Process
HTML
Database
•Insecure
•Platform dependent
•Inefficient
![Page 5: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/5.jpg)
CGI vs. Servlet
• Servlet is Sun’s solution for CGI
• Both generate dynamic contents
• Servlet is light
• Servlet is secure
• Servlet is platform independent
• Servlet has better support for reusable component
![Page 6: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/6.jpg)
Java Server Definition
• An instance of Java Virtual Machine
• One Java Server can support multiple concurrent services
• Java Server can start: administrative services HTTP services web proxy services
• Services are configured when server process is initiated
![Page 7: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/7.jpg)
Java Servlet Definition
• Java class that runs in JVM associated with Server
• Java object that conforms to a specific interface defined by the server architecture
• Loaded and invoked by services
• Multithreading
• Extends the functionality of the server
![Page 8: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/8.jpg)
Server and Servlet Interaction
Browser
HTTP
Web Server
Servlet Engine
Servlets
HTML
Database
Application
Business Log.
![Page 9: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/9.jpg)
Demo and Servlet Life Cycle
Application Server
Servlet Engine
Init()
Service ()doGet ()
doPost ()
Destroy()
Do… ()
link to Utopia
HttpResponse
HttpRequest
PrintWriter
link to Laptop
![Page 10: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/10.jpg)
Simple Sample (Hello World)
import java.io.*;import javax.servlet.*;import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><head><title>"); out.println("Hello World!</title>"); out.println("</head><body>"); out.println("<h1>Hello World!</h1>"); out.println("</body></html>");
}}
![Page 11: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/11.jpg)
Servlet Functions
• Reads data sent by user
• Looks up information from HTTP request
• Connects to database
• Invokes legacy application
• Executes RMI or CORBA calls
• Executes algorithm
• Formats document
• Sends document back to clients
![Page 12: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/12.jpg)
Servlets
Algorithm
JDBC
PANDA
Project Group Assignment Servlets in Action
Tomcat
HTTP
Link to Laptoplink to Utopia
![Page 13: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/13.jpg)
Servlet with Synchronization…
public class AlgorithmRequest extends HttpServlet {public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
PrintWriter output; response.setContentType("text/html"); output = response.getWriter();
if(getConnection()){ String SemesterCourse =
request.getParameter("SEMESTERCOURSE"); synchronized (this) { AlgorithmControl ac = new
AlgorithmControl(SemesterCourse); …………………………………………
![Page 14: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/14.jpg)
Servlet Advantanges
• Convenient
• Efficient (light weight thread, memory)
• Inexpensive
• Keep intellectual properties on the server
• Portable
• Powerful
• Secure
![Page 15: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/15.jpg)
Server Advantanges
• Efficient Memory management Light weight
• Platform independent
• Thread-safe
![Page 16: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/16.jpg)
Server Considerations
• Java is slower than C++
• However, Java server uses threads
![Page 17: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/17.jpg)
• WebSphere from IBM
• WebLogic from BEA
• 9i Application Server from Oracle
• Jrun from Allaire
• iPlanet from Sun
• Tomcat from Apache
Java Servers or Engines
![Page 18: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/18.jpg)
Apache and Tomcat
• Industrial strength Web server
• Tomcat is a servlet engine that can be plugged in with Apache
• Apache and Tomcat can be down loaded from http://jakarta.apache.org
• FREE!
![Page 19: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/19.jpg)
Servlet vs. PHP
• PHP also free open source
• PHP consists of tags in HTML document
• Servlet is more widely supported
• Servlet is written in Java with extensive API for: database access distributed objects networking
![Page 20: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/20.jpg)
Servlet vs. ASP
• ASP is a competing technology from Microsoft
• Servlet is portable to other operating systems web servers
• Servlet is more powerful for complex applications
• Better support for reusable components
![Page 21: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/21.jpg)
Conclusion
• Java server and servlet are Economical Portable Powerful Secure
![Page 22: Java Server and Servlet](https://reader035.fdocuments.us/reader035/viewer/2022062217/56814027550346895dab8882/html5/thumbnails/22.jpg)
Thank You