1 / 50

Java Servlets Tutorial | Java Servlets Explained | Java Tutorial For Beginners | Simplilearn

This presentation on Java Servlets tutorial will help you with the fundementals of Java servlets and will also help you with a practial part to set up the environment servets and execute a practical program. <br><br>About Simplilearn Java certification training course:<br>If youu2019re looking to master web application development for virtually any computing platform, this Java Certification Training course is for you. This all-in-one Java training will give you a firm foundation in Java, the most commonly used programming language in software development.<br><br>This advanced Java Certification Training course is designed to guide you through the concepts of Java from introductory techniques to advanced programming skills. The course will provide you with the knowledge of Core Java 8, operators, arrays, loops, methods, and constructors while giving you hands-on experience in JDBC and JUnit framework.<br><br>Java Certification Course Key Features:<br>1. 70 hours of blended training<br>2. Hands-on coding and implementation of two web-based projects<br>3. Includes Hibernate and Spring frameworks<br>4. 35 coding-related exercises on Core Java 8<br>5. Lifetime access to self-paced learning<br>6. Flexibility to choose classes<br><br>Eligibility:<br>Simplilearnu2019s Java Certification Training course is ideal for software developers, web designers, programming enthusiasts, engineering graduates, and students or professionals who wish to become Java developers.<br><br>Pre-requisites:<br>Prior knowledge of Core Java is a prerequisite to taking this advanced Java Certification training course. Our Core Java online self-paced course is available for free to become familiar with the basics of Java programming.<br><br>ud83dudc49Learn more at: https://bit.ly/3b6SCvp<br><br>

Simplilearn
Télécharger la présentation

Java Servlets Tutorial | Java Servlets Explained | Java Tutorial For Beginners | Simplilearn

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Agenda What is a Java Servlet? Java Servlet Life-Cycle Java Servlet Architecture Java Servlet Features Java Servlet Advantages Java Servlet Disadvantages CGI CGI v/s Servlet Request and Response Session Tracking and Cookies

  2. What is Java Servlet?

  3. Click here to watch the video

  4. What is Java Servlet? Request Response

  5. What is Java Servlet? Web Application Servlet - 1 Servlet - 2 Servlet Container

  6. What is Java Servlet? A Servlet is part of a Java web application. A Java Servlet is a Java object that responds to HTTP requests It runs inside a Servlet container A Servlet container is capable to run multiple web applications at the same time, each having multiple servlets running inside Servlet - 1 Servlet

  7. Java Servlet Life-Cycle

  8. Java Servlet Life-Cycle • Java servlet life cycle involves the following throughout is lifecycle • We initialize the servlet by calling the init() method. • The servlet calls service() for processing the client's request. • We terminate the servlet by calling the destroy() method. • At the end, servlet is dumped by the garbage collector. Servlet

  9. Java Servlet Life-Cycle • The init() method is called only once in the entire process. It is called only when the servlet is created. • public void init() throwsServletException { • //Statements; • } init()

  10. Java Servlet Life-Cycle The service() method is the main method desfined to perform the actual task required. public void service(ServletRequestRq, ServletResponse Rs) throwsServletException,IOException { //Statements; } service()

  11. Java Servlet Life-Cycle A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method. public void doGet(ServletRequestRq, ServletResponse Rs) throwsServletException,IOException { //Statements; } doGet()

  12. Java Servlet Life-Cycle A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method. public void doPost(ServletRequestRq, ServletResponse Rs) throwsServletException,IOException { //Statements; } doPost()

  13. Java Servlet Life-Cycle • The destroy() method is called only once in the end of the entire process. It is called only when the servlet is terminated. • public void destroy() { • //Destroy-Statements; • } destroy()

  14. Java Servlet Architecture

  15. Java Servlet Architecture Web Application Servlet - 1 Request Servlet Container Response Threads destroy() service() init()

  16. Java Servlet Features

  17. Java Servlet Features Java Servlets are Portable in nature 1 2 3 4 Java Servlets are Scalable and Efficient Java Servlets are Robust in nature Java Servlets are Secure

  18. Environment Setup

  19. Example

  20. Java Servlet Advantages

  21. Java Servlet Advantages • Servlet is convenient in modifying regular HTML • We can write the servlet code into the JSP • Servlets includes the feature of multithreading of java • We can make use of exception handling of java • Servlets have a separate layer of business logic in the application • Easy for developers to show and process the information

  22. Java Servlet Disadvantages

  23. Java Servlet Disadvantages • Designing in servlet is complicated • Servlets often slow down the application • Business logic of Servlet is difficult to understand • We need a JRE on the server to run servlets • Database Connectivity is complicated

  24. CGI

  25. CGI CGI (Common Gateway Interface) allows the web server to call an external program and pass HTTP request to the external program to process the request

  26. CGI Server http CGI Shell-1 CGI Program CGI Shell-2 Request CGI Shell-3 Common Gateway Interface

  27. CGI V/S Servlet

  28. CGI V/S Servlet CGI Servlet CGI Scripts are executable codes written in native OS Servlets are written and run in JVM Performance is low Performance is high Platform independent Hard to switch between platforms Servlets are translated to bytecode CGI scripts are directly executed Servlets are potable CGI is not portable

  29. Servlet Request

  30. Servlet Request HttpRequest The HttpRequest object is used to represent the HTTP request to a browser that the user sends to the web application. Thus, anything the browser sends, is accessible through the HttpRequest.

  31. Servlet Request Request Parameter The request parameters are parameters that are sent from the browser along with the request. Request parameters are typically sent as part of the URL, or as part of the body of an HTTP request.

  32. Servlet Request Request Header The request headers are name, value pairs sent by the browser along with the HTTP request. The request headers contain information about what browser software is being used, what file types the browser can receive.

  33. Servlet Request InputStream If the browser sends an HTTP POST request, request parameters and other potential data is sent to the server in the HTTP request body. It doesn't have to be request parameters that is sent in the HTTP request body. It could be pretty much any data, like a file or a SOAP request.

  34. Servlet Request Request Session The session object can hold information about a given user, between requests. So, if you set an object into the session object during one request, it will be available for you to read during any subsequent requests within the same session time scope.

  35. Servlet Request ServletContext The ServletContext contains the metadata related to the application.

  36. Servlet Response

  37. Servlet Response HttpResponse The HttpResponse object is used to represent the HTTP response to your request. A web application sends back a response page to the user as a response to the HTTP request from the browser sent to your web application.

  38. Servlet Response WriteHTML To initiate the process of sending the html back to the browser, you need to retrieve the PrintWriter from the Httpresponse object.

  39. Servlet Response Response Header Similar to Httprequest, the Httpresponse includes headers as well. These are responsible for all the data written in the response.

  40. Servlet Response Content-Type The Content-Type header is responsible to tell the browser about the type of content you are sending in return

  41. Servlet Response Content-Length The Content-Length header is responsible for telling you about the number of bytes your servlet is sending in return

  42. Servlet Response Redirection Redirecting will help you to redirect yourself to a different webpage from the current one.

  43. Session Tracking

  44. Session Tracking In servlets, Session Tracking is a simple procedure used to maintain the various types of data related to a specific user. The Data may be is search history, login credentials, etc. It is also known as session management in servlet.

  45. Session Tracking Request (Second) Request Response User Server

  46. Cookies

  47. Cookies A cookie is a small piece of information that is persisted between the multiple client requests. A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.

  48. Cookies Request Cookie Request Response Cookie User Server

More Related