This document provides an overview of Java servlets including:
- What a Java servlet is and why they are used to generate dynamic web content
- The basic servlet architecture including the servlet lifecycle and how requests are handled
- Examples of simple servlets like one that displays a greeting based on a request parameter and an image counter servlet
- How servlets are deployed and configured using the Eclipse IDE
The document provides information on servlet fundamentals including definitions, applications, architecture, lifecycle, and development process. Some key points include:
- Servlets are Java programs that run on web servers and interact with clients via HTTP requests and responses. They provide dynamic content and process user input.
- Common servlet applications include search engines, e-commerce sites, and intranets.
- The servlet lifecycle includes initialization, processing requests, and destruction. Servlets remain loaded in memory between requests for improved performance over CGI.
- To develop a servlet, you create a class that implements the Servlet interface, define request handling methods, compile it, deploy it in a web container
The document provides an overview of servlets, including:
- Servlets allow generating dynamic web content and communication with other server resources like databases.
- The servlet lifecycle includes initialization, handling requests, and destruction.
- Servlets extend HttpServlet to handle HTTP requests and responses, overriding methods like doGet() and doPost().
- The web container manages servlets, providing threading and other services.
This document provides information on servlets including:
- Servlets allow dynamic content and interaction for web applications and can be used to build search engines, e-commerce sites, and more.
- Servlets have better performance than CGI since they remain loaded in memory between requests rather than starting a new process for each request.
- Servlets follow a request-response lifecycle and provide APIs to handle HTTP requests and responses through the Servlet, HttpServletRequest, and HttpServletResponse interfaces.
Java Servlet Programming under Ubuntu Linux by Tushar B KuteTushar B Kute
The document provides information on programming simple servlets under Ubuntu GNU/Linux. It discusses what can be built with servlets, the benefits of servlets over CGI, definitions of servlet containers and servlet architecture. It also covers the servlet lifecycle, request and response objects, and the steps to write a simple servlet class, compile it, deploy it on Tomcat, and run it.
Server-side programming with Java servlets allows dynamic web content generation. Servlets extend the capabilities of web servers by responding to incoming requests. A servlet is a Java class that implements the servlet interface. It handles HTTP requests and responses by overriding methods like doGet() and doPost(). Servlets provide better performance than CGI by using threads instead of processes to handle requests. They also offer portability, robustness, and security due to being implemented in Java. Sessions allow servlets to maintain state across multiple requests from the same user by utilizing session IDs stored in cookies.
Server-side programming with Java servlets allows dynamic web content generation. A servlet is a Java class that extends HTTP servlet functionality. It handles HTTP requests and responses by overriding methods like doGet() and doPost(). Servlets offer benefits over older CGI technologies like improved performance through multithreading and portability through the Java programming language. Servlets communicate with clients via HTTP request and response objects, and can establish sessions to identify users across multiple requests.
The document discusses Java servlets and server-side programming. It defines servlets as Java programs that extend the capabilities of web servers. Servlets can respond dynamically to web requests and are used to create dynamic web content. The document outlines the servlet lifecycle and how servlets handle HTTP requests and responses through request and response objects. It also discusses advantages of servlets like performance and portability compared to older CGI technologies.
Integrating Servlets and JSP (The MVC Architecture)Amit Ranjan
This document discusses integrating servlets and JSP using the MVC architecture. It begins with an introduction to the MVC pattern, explaining the model, view, and controller components. It then covers advantages of MVC like separation of concerns and reusability. Next, it describes how MVC applies to servlets, with the servlet acting as controller and JSP as view. It explains how the web deployment descriptor (web.xml) provides initialization parameters and how servlets can forward requests to JSP. Finally, it discusses attributes, threading safety, and accessing initialization parameters from JSP.
This document provides an overview of Java servlets technology, including:
1. What Java servlets are and their main purposes and advantages such as portability, power, and integration with server APIs.
2. Key aspects of servlet architecture like the servlet lifecycle, the HttpServletRequest and HttpServletResponse objects, and how different HTTP methods map to servlet methods.
3. Examples of simple servlets that process parameters, maintain a session counter, and examples of deploying servlets in Eclipse IDE.
This document provides information about the 20CS4104 Internet Programming course, including course outcomes, objectives, topics covered, and the course delivery plan. The key topics covered include installing and configuring the Apache Tomcat web server, Java servlets, servlet life cycle, form GET and POST actions, session handling, JDBC and database connectivity, and Java Server Pages. The course outcomes focus on learning server-side programming using servlets, JSP, and database connectivity. The document lists the topics that will be covered in each session.
This document provides an overview of servlets and JSPs. It discusses how servlets were developed to address disadvantages of CGI programs. Servlets run within a web container and have a lifecycle of init(), service(), and destroy() methods. The document also covers implementing a simple servlet, using HttpServletRequest and HttpServletResponse objects, and configuring servlets in web.xml. It describes how JSPs work by being converted to servlets and discusses JSP directives, actions, and scripting elements.
- Dynamic content generation is needed to satisfy user needs that cannot be met with static content alone, such as data from databases or responses to queries. This requires server-side architectures that dynamically generate content.
- HTTP is a stateless protocol in which each client request is associated with a method like GET or POST specifying the desired action. GET retrieves information while POST submits information of unlimited length in the request body.
- A Java servlet is a pluggable program that extends server functionality. Servlets run inside a servlet container on the server and are portable across systems.
This document provides an overview of server-side technologies including Servlets and JavaServer Pages (JSP). It discusses the Servlet lifecycle, architecture, advantages over CGI, and software requirements. It also introduces the Tomcat web server, its components, and how to configure Tomcat in Eclipse. The document outlines steps to create and run sample servlet code and manage sessions.
This document provides an overview of server-side technologies, specifically focusing on servlets and Tomcat. It begins with an introduction to servlets, covering their lifecycle, advantages over CGI, and architecture. It then discusses Tomcat, the requirements to run servlets, and how to configure Tomcat in Eclipse. The document outlines the steps to create and run a sample servlet program in Eclipse. It provides examples of servlet code to print "Hello World", read form data, and manage sessions. Overall, the document serves as a tutorial on servlets and Tomcat for educational purposes.
J2EE : Java servlet and its types, environmentjoearunraja2
The server-side extensions are nothing but the technologies that are used to create dynamic Web pages. Actually, to provide the facility of dynamic Web pages, Web pages need a container or Web server. To meet this requirement, independent Web server providers offer some proprietary solutions in the form of APIs (Application Programming Interface).
These APIs allow us to build programs that can run with a Web server. In this case, Java Servlet is also one of the component APIs of Java Platform Enterprise Edition (nowadays known as – ‘Jakarta EE’) which sets standards for creating dynamic Web applications in Java.
Today we all are aware of the need to create dynamic web pages i.e. the ones that can change the site contents according to the time or can generate the content according to the request received by the client. If you like coding in Java, then you will be happy to know that using Java there also exists a way to generate dynamic web pages and that way is Java Servlet. But before we move forward with our topic let’s first understand the need for server-side extensions.
Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the web server, process the request, produce the response, and then send a response back to the web server. Servlet is faster than CGI as it doesn’t involve the creation of a new process for every new request received.
Servlets, as written in Java, are platform independent.
Removes the overhead of creating a new process for each request as Servlet doesn’t run in a separate process. There is only a single instance that handles all requests concurrently. This also saves the memory and allows a Servlet to easily manage the client state.
It is a server-side component, so Servlet inherits the security provided by the Web server.
The API designed for Java Servlet automatically acquires the advantages of the Java platforms such as platform-independent and portability. In addition, it obviously can use the wide range of APIs created on Java platforms such as JDBC to access the database.
Many Web servers that are suitable for personal use or low-traffic websites are offered for free or at extremely cheap costs eg. Java servlet. However, the majority of commercial-grade Web servers are rather expensive, with the notable exception of Apache, which is free.
The Servlet Container
Servlet container, also known as Servlet engine, is an integrated set of objects that provide a run time environment for Java Servlet components. In simple words, it is a system that manages Java Servlet components on top of the Web server to handle the Web client requests.
Services provided by the Servlet container:
Network Services: Loads a Servlet class. The loading may be from a local file system, a remote file system or other network services. The Servlet container provides the network services over which the request and response are sent.
The document discusses servlets, including their life cycle, handling HTTP requests and responses, and session tracking using cookies. It provides details on:
- The init(), service(), and destroy() methods that are central to a servlet's life cycle.
- How servlets can read data from HTTP requests using the HttpServletRequest interface and write data to HTTP responses using the HttpServletResponse interface.
- How servlets can maintain session state across requests using the HttpSession interface and cookies.
- Examples of simple servlets that retrieve and display request parameters, and handle GET and POST requests.
Servlet API life cycle methods
init(): called when servlet is instantiated; must return before any other methods will be called
service(): method called directly by server when an HTTP request is received; default service() method calls doGet() (or related methods covered later)
destroy(): called when server shuts down
Server-side programming with Java servlets allows dynamic web content generation. Servlets extend the capabilities of web servers by responding to incoming requests. A servlet is a Java class that implements the servlet interface. It handles HTTP requests and responses by overriding methods like doGet() and doPost(). Servlets provide better performance than CGI by using threads instead of processes to handle requests. They also offer portability, robustness, and security due to being implemented in Java. Sessions allow servlets to maintain state across multiple requests from the same user by utilizing session IDs stored in cookies.
Server-side programming with Java servlets allows dynamic web content generation. A servlet is a Java class that extends HTTP servlet functionality. It handles HTTP requests and responses by overriding methods like doGet() and doPost(). Servlets offer benefits over older CGI technologies like improved performance through multithreading and portability through the Java programming language. Servlets communicate with clients via HTTP request and response objects, and can establish sessions to identify users across multiple requests.
The document discusses Java servlets and server-side programming. It defines servlets as Java programs that extend the capabilities of web servers. Servlets can respond dynamically to web requests and are used to create dynamic web content. The document outlines the servlet lifecycle and how servlets handle HTTP requests and responses through request and response objects. It also discusses advantages of servlets like performance and portability compared to older CGI technologies.
Integrating Servlets and JSP (The MVC Architecture)Amit Ranjan
This document discusses integrating servlets and JSP using the MVC architecture. It begins with an introduction to the MVC pattern, explaining the model, view, and controller components. It then covers advantages of MVC like separation of concerns and reusability. Next, it describes how MVC applies to servlets, with the servlet acting as controller and JSP as view. It explains how the web deployment descriptor (web.xml) provides initialization parameters and how servlets can forward requests to JSP. Finally, it discusses attributes, threading safety, and accessing initialization parameters from JSP.
This document provides an overview of Java servlets technology, including:
1. What Java servlets are and their main purposes and advantages such as portability, power, and integration with server APIs.
2. Key aspects of servlet architecture like the servlet lifecycle, the HttpServletRequest and HttpServletResponse objects, and how different HTTP methods map to servlet methods.
3. Examples of simple servlets that process parameters, maintain a session counter, and examples of deploying servlets in Eclipse IDE.
This document provides information about the 20CS4104 Internet Programming course, including course outcomes, objectives, topics covered, and the course delivery plan. The key topics covered include installing and configuring the Apache Tomcat web server, Java servlets, servlet life cycle, form GET and POST actions, session handling, JDBC and database connectivity, and Java Server Pages. The course outcomes focus on learning server-side programming using servlets, JSP, and database connectivity. The document lists the topics that will be covered in each session.
This document provides an overview of servlets and JSPs. It discusses how servlets were developed to address disadvantages of CGI programs. Servlets run within a web container and have a lifecycle of init(), service(), and destroy() methods. The document also covers implementing a simple servlet, using HttpServletRequest and HttpServletResponse objects, and configuring servlets in web.xml. It describes how JSPs work by being converted to servlets and discusses JSP directives, actions, and scripting elements.
- Dynamic content generation is needed to satisfy user needs that cannot be met with static content alone, such as data from databases or responses to queries. This requires server-side architectures that dynamically generate content.
- HTTP is a stateless protocol in which each client request is associated with a method like GET or POST specifying the desired action. GET retrieves information while POST submits information of unlimited length in the request body.
- A Java servlet is a pluggable program that extends server functionality. Servlets run inside a servlet container on the server and are portable across systems.
This document provides an overview of server-side technologies including Servlets and JavaServer Pages (JSP). It discusses the Servlet lifecycle, architecture, advantages over CGI, and software requirements. It also introduces the Tomcat web server, its components, and how to configure Tomcat in Eclipse. The document outlines steps to create and run sample servlet code and manage sessions.
This document provides an overview of server-side technologies, specifically focusing on servlets and Tomcat. It begins with an introduction to servlets, covering their lifecycle, advantages over CGI, and architecture. It then discusses Tomcat, the requirements to run servlets, and how to configure Tomcat in Eclipse. The document outlines the steps to create and run a sample servlet program in Eclipse. It provides examples of servlet code to print "Hello World", read form data, and manage sessions. Overall, the document serves as a tutorial on servlets and Tomcat for educational purposes.
J2EE : Java servlet and its types, environmentjoearunraja2
The server-side extensions are nothing but the technologies that are used to create dynamic Web pages. Actually, to provide the facility of dynamic Web pages, Web pages need a container or Web server. To meet this requirement, independent Web server providers offer some proprietary solutions in the form of APIs (Application Programming Interface).
These APIs allow us to build programs that can run with a Web server. In this case, Java Servlet is also one of the component APIs of Java Platform Enterprise Edition (nowadays known as – ‘Jakarta EE’) which sets standards for creating dynamic Web applications in Java.
Today we all are aware of the need to create dynamic web pages i.e. the ones that can change the site contents according to the time or can generate the content according to the request received by the client. If you like coding in Java, then you will be happy to know that using Java there also exists a way to generate dynamic web pages and that way is Java Servlet. But before we move forward with our topic let’s first understand the need for server-side extensions.
Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the web server, process the request, produce the response, and then send a response back to the web server. Servlet is faster than CGI as it doesn’t involve the creation of a new process for every new request received.
Servlets, as written in Java, are platform independent.
Removes the overhead of creating a new process for each request as Servlet doesn’t run in a separate process. There is only a single instance that handles all requests concurrently. This also saves the memory and allows a Servlet to easily manage the client state.
It is a server-side component, so Servlet inherits the security provided by the Web server.
The API designed for Java Servlet automatically acquires the advantages of the Java platforms such as platform-independent and portability. In addition, it obviously can use the wide range of APIs created on Java platforms such as JDBC to access the database.
Many Web servers that are suitable for personal use or low-traffic websites are offered for free or at extremely cheap costs eg. Java servlet. However, the majority of commercial-grade Web servers are rather expensive, with the notable exception of Apache, which is free.
The Servlet Container
Servlet container, also known as Servlet engine, is an integrated set of objects that provide a run time environment for Java Servlet components. In simple words, it is a system that manages Java Servlet components on top of the Web server to handle the Web client requests.
Services provided by the Servlet container:
Network Services: Loads a Servlet class. The loading may be from a local file system, a remote file system or other network services. The Servlet container provides the network services over which the request and response are sent.
The document discusses servlets, including their life cycle, handling HTTP requests and responses, and session tracking using cookies. It provides details on:
- The init(), service(), and destroy() methods that are central to a servlet's life cycle.
- How servlets can read data from HTTP requests using the HttpServletRequest interface and write data to HTTP responses using the HttpServletResponse interface.
- How servlets can maintain session state across requests using the HttpSession interface and cookies.
- Examples of simple servlets that retrieve and display request parameters, and handle GET and POST requests.
Servlet API life cycle methods
init(): called when servlet is instantiated; must return before any other methods will be called
service(): method called directly by server when an HTTP request is received; default service() method calls doGet() (or related methods covered later)
destroy(): called when server shuts down
Number theory concepts like prime numbers, modular arithmetic, and theorems like Fermat's and Euler's are important foundations for cryptography. Primality testing and the Chinese Remainder Theorem can help efficiently generate and operate with large prime numbers. While exponentiation is easy, the inverse problem of computing discrete logarithms is computationally difficult, making it suitable for cryptographic applications.
This document provides an overview of a university course on network and computer security. It outlines the course structure, including topics on cryptography, network security concepts, and laboratory exercises. It also defines key security terms like threats, attacks, security services, and security mechanisms.
Fluid mechanics is the branch of physics concerned with the mechanics of fluids (liquids, gases, and plasmas) and the forces on them. Originally applied to water (hydromechanics), it found applications in a wide range of disciplines, including mechanical, aerospace, civil, chemical, and biomedical engineering, as well as geophysics, oceanography, meteorology, astrophysics, and biology.
It can be divided into fluid statics, the study of various fluids at rest, and fluid dynamics.
Fluid statics, also known as hydrostatics, is the study of fluids at rest, specifically when there's no relative motion between fluid particles. It focuses on the conditions under which fluids are in stable equilibrium and doesn't involve fluid motion.
Fluid kinematics is the branch of fluid mechanics that focuses on describing and analyzing the motion of fluids, such as liquids and gases, without considering the forces that cause the motion. It deals with the geometrical and temporal aspects of fluid flow, including velocity and acceleration. Fluid dynamics, on the other hand, considers the forces acting on the fluid.
Fluid dynamics is the study of the effect of forces on fluid motion. It is a branch of continuum mechanics, a subject which models matter without using the information that it is made out of atoms; that is, it models matter from a macroscopic viewpoint rather than from microscopic.
Fluid mechanics, especially fluid dynamics, is an active field of research, typically mathematically complex. Many problems are partly or wholly unsolved and are best addressed by numerical methods, typically using computers. A modern discipline, called computational fluid dynamics (CFD), is devoted to this approach. Particle image velocimetry, an experimental method for visualizing and analyzing fluid flow, also takes advantage of the highly visual nature of fluid flow.
Fundamentally, every fluid mechanical system is assumed to obey the basic laws :
Conservation of mass
Conservation of energy
Conservation of momentum
The continuum assumption
For example, the assumption that mass is conserved means that for any fixed control volume (for example, a spherical volume)—enclosed by a control surface—the rate of change of the mass contained in that volume is equal to the rate at which mass is passing through the surface from outside to inside, minus the rate at which mass is passing from inside to outside. This can be expressed as an equation in integral form over the control volume.
The continuum assumption is an idealization of continuum mechanics under which fluids can be treated as continuous, even though, on a microscopic scale, they are composed of molecules. Under the continuum assumption, macroscopic (observed/measurable) properties such as density, pressure, temperature, and bulk velocity are taken to be well-defined at "infinitesimal" volume elements—small in comparison to the characteristic length scale of the system, but large in comparison to molecular length scale
Concept of Problem Solving, Introduction to Algorithms, Characteristics of Algorithms, Introduction to Data Structure, Data Structure Classification (Linear and Non-linear, Static and Dynamic, Persistent and Ephemeral data structures), Time complexity and Space complexity, Asymptotic Notation - The Big-O, Omega and Theta notation, Algorithmic upper bounds, lower bounds, Best, Worst and Average case analysis of an Algorithm, Abstract Data Types (ADT)
☁️ GDG Cloud Munich: Build With AI Workshop - Introduction to Vertex AI! ☁️
Join us for an exciting #BuildWithAi workshop on the 28th of April, 2025 at the Google Office in Munich!
Dive into the world of AI with our "Introduction to Vertex AI" session, presented by Google Cloud expert Randy Gupta.
International Journal of Distributed and Parallel systems (IJDPS)samueljackson3773
The growth of Internet and other web technologies requires the development of new
algorithms and architectures for parallel and distributed computing. International journal of
Distributed and parallel systems is a bimonthly open access peer-reviewed journal aims to
publish high quality scientific papers arising from original research and development from
the international community in the areas of parallel and distributed systems. IJDPS serves
as a platform for engineers and researchers to present new ideas and system technology,
with an interactive and friendly, but strongly professional atmosphere.
Analysis of reinforced concrete deep beam is based on simplified approximate method due to the complexity of the exact analysis. The complexity is due to a number of parameters affecting its response. To evaluate some of this parameters, finite element study of the structural behavior of the reinforced self-compacting concrete deep beam was carried out using Abaqus finite element modeling tool. The model was validated against experimental data from the literature. The parametric effects of varied concrete compressive strength, vertical web reinforcement ratio and horizontal web reinforcement ratio on the beam were tested on eight (8) different specimens under four points loads. The results of the validation work showed good agreement with the experimental studies. The parametric study revealed that the concrete compressive strength most significantly influenced the specimens’ response with the average of 41.1% and 49 % increment in the diagonal cracking and ultimate load respectively due to doubling of concrete compressive strength. Although the increase in horizontal web reinforcement ratio from 0.31 % to 0.63 % lead to average of 6.24 % increment on the diagonal cracking load, it does not influence the ultimate strength and the load-deflection response of the beams. Similar variation in vertical web reinforcement ratio leads to an average of 2.4 % and 15 % increment in cracking and ultimate load respectively with no appreciable effect on the load-deflection response.
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfMohamedAbdelkader115
Glad to be one of only 14 members inside Kuwait to hold this credential.
Please check the members inside kuwait from this link:
https://www.rics.org/networking/find-a-member.html?firstname=&lastname=&town=&country=Kuwait&member_grade=(AssocRICS)&expert_witness=&accrediation=&page=1
Raish Khanji GTU 8th sem Internship Report.pdfRaishKhanji
This report details the practical experiences gained during an internship at Indo German Tool
Room, Ahmedabad. The internship provided hands-on training in various manufacturing technologies, encompassing both conventional and advanced techniques. Significant emphasis was placed on machining processes, including operation and fundamental
understanding of lathe and milling machines. Furthermore, the internship incorporated
modern welding technology, notably through the application of an Augmented Reality (AR)
simulator, offering a safe and effective environment for skill development. Exposure to
industrial automation was achieved through practical exercises in Programmable Logic Controllers (PLCs) using Siemens TIA software and direct operation of industrial robots
utilizing teach pendants. The principles and practical aspects of Computer Numerical Control
(CNC) technology were also explored. Complementing these manufacturing processes, the
internship included extensive application of SolidWorks software for design and modeling tasks. This comprehensive practical training has provided a foundational understanding of
key aspects of modern manufacturing and design, enhancing the technical proficiency and readiness for future engineering endeavors.
Value Stream Mapping Worskshops for Intelligent Continuous SecurityMarc Hornbeek
This presentation provides detailed guidance and tools for conducting Current State and Future State Value Stream Mapping workshops for Intelligent Continuous Security.
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...Infopitaara
A feed water heater is a device used in power plants to preheat water before it enters the boiler. It plays a critical role in improving the overall efficiency of the power generation process, especially in thermal power plants.
🔧 Function of a Feed Water Heater:
It uses steam extracted from the turbine to preheat the feed water.
This reduces the fuel required to convert water into steam in the boiler.
It supports Regenerative Rankine Cycle, increasing plant efficiency.
🔍 Types of Feed Water Heaters:
Open Feed Water Heater (Direct Contact)
Steam and water come into direct contact.
Mixing occurs, and heat is transferred directly.
Common in low-pressure stages.
Closed Feed Water Heater (Surface Type)
Steam and water are separated by tubes.
Heat is transferred through tube walls.
Common in high-pressure systems.
⚙️ Advantages:
Improves thermal efficiency.
Reduces fuel consumption.
Lowers thermal stress on boiler components.
Minimizes corrosion by removing dissolved gases.
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxRishavKumar530754
LiDAR-Based System for Autonomous Cars
Autonomous Driving with LiDAR Tech
LiDAR Integration in Self-Driving Cars
Self-Driving Vehicles Using LiDAR
LiDAR Mapping for Driverless Cars
ELectronics Boards & Product Testing_Shiju.pdfShiju Jacob
This presentation provides a high level insight about DFT analysis and test coverage calculation, finalizing test strategy, and types of tests at different levels of the product.
2. Contents
1. The life cycle of a servlet;
2. A simple servlet;
3. the servlet API;
4. The javax.servlet package
5. Reading servlet parameter;
6. the javax.servlet.http package;
7. Handling HTTP Requests and
Responses;
8. using Cookies;
3. Contents
9. Session Tracking,
10. Java Server Pages (JSP); JSP tags,
Variables and Objects, Methods,
11. Control statements, Loops,
12. Request String,
13. Parsing other information,
14. User sessions,
15. Cookies, Session Objects
5. Background
How web browsers and servers cooperate to provide content to a
user?
• Consider a request for a static web page. A user enters a URL into
a browser. The browser generates an HTTP request to the
appropriate web server.
• The web server maps this request to a specific file. That file is
returned in an HTTP response to the browser. The HTTP header in
the response indicates the type of the content.
• The Multipurpose Internet Mail Extensions (MIME) are used for
this purpose.
• For example, ordinary ASCII text has a MIME type of text/plain.
The Hypertext Markup Language (HTML) source code of a web
page has a MIME type of text/html.
7. WhatisaJavaServlets?
• A Java servlet is a server-side program that is called
by the user interface or another J2EE component and
contains the business logic to process a request.
• A Java Server Page is also a server-side program that
performs practically the same duties as a Java servlet
using a different technique.
• Both a Java servlet and a Java Server Page call other
components that handle processing details.
8. ServletServices
• Java Servlets provide many useful services
Provides low-level API for building Internet services
Serves as foundation to JavaServer Pages (JSP) and
JavaServer Faces (JSF) technologies
Can deliver multiple types of data to any client
XML, HTML, WML, GIF, etc...
Can serve as “Controller” of JSP/Servlet application
9. WhyUseServlets?
• Portability
Write once, serve everywhere
• Power
Can take advantage of all Java APIs
• Elegance
Simplicity due to abstraction
• Efficiency & Endurance
Highly scalable
10. WhyUseServlets?
• Safety
Strong type-checking
Memory management
• Integration
Servlets tightly coupled with server
• Extensibility & Flexibility
Servlets designed to be easily extensible, though
currently optimized for HTTP uses
Flexible invocation of servlet (SSI, servlet-chaining,
filters, etc.)
11. ASimpleServlet
• To become familiar with the key servlet concepts, we
will begin by building and testing a simple servlet.
• The basic steps are the following:
1. Create and compile the servlet source code. Then,
copy the servlet’s class file to the proper directory,
and add the servlet’s name and mappings to the
proper web.xml file.
2. Start Tomcat.
3. Start a web browser and request the servlet.
12. TimeServlet–Example
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TimeServlet extends HttpServlet {
public void doGet(HttpServletRequest aRequest,
HttpServletResponse aResponse)
throws ServletException, IOException {
PrintWriter out = aResponse.getWriter();
out.println("<HTML>");
out.println("The time is: " +
new java.util.Date());
out.println("</HTML>");
}
}
14. ServletsArchitecture
• The HttpServlet class
Serves client's HTTP requests
• For each of the HTTP methods, GET, POST, and
others, there is corresponding method:
doGet(…) – serves HTTP GET requests
doPost(…) – serves HTTP POST requests
doPut(…), doHead(…), doDelete(…), doTrace(…),
doOptions(…)
• The Servlet usually must implement one of the
first two methods or the service(…) method
15. ServletsArchitecture
• The HttpServletRequest object
Contains the request data from the client
HTTP request headers
Form data and query parameters
Other client data (cookies, path, etc.)
• The HttpServletResponse object
Encapsulates data sent back to client
HTTP response headers (content type, cookies,
etc.)
Response body (as OutputStream)
16. ServletsArchitecture
• The HTTP GET method is used when:
The processing of the request does not change the state of
the server
The amount of form data is small
You want to allow the request to be bookmarked
• The HTTP POST method is used when:
The processing of the request changes the state of the
server, e.g. storing data in a DB
The amount of form data is large
The contents of the data should not be visible in the URL
(for example, passwords)
18. ServletsLife-Cycle
• You can provide an implementation of these methods
in HttpServlet descendent classes to manipulate the
servlet instance and the resources it depends on
• The Web container
manages the life cycle
of servlet instances
• The life-cycle methods
should not be called by
your code
init()
...()
service()
doGet()
doPost()
doDelete()
destroy()
doPut()
New Destroyed
Running
20. Theinit()Method
• Called by the Web container when the servlet
instance is first created
• The Servlets specification guarantees that no
requests will be processed by this servlet until the
init() method has completed
• Override the init() method when:
You need to create or open any servlet-specific
resources that you need for processing user
requests
You need to initialize the state of the servlet
public void init (ServletConfig config)
throws ServletException
21. Theservice()Method
• Called by the Web container to process a user
request
• Dispatches the HTTP requests to doGet(…),
doPost(…), etc. depending on the HTTP request
method (GET, POST, and so on)
Sends the result as HTTP response
• Usually we do not need to override this method
public void service (ServletRequest request,
ServletResponse response) throws ServletException,IOException
22. Thedestroy()Method
• Called by the Web container when the servlet
instance is being eliminated
• The Servlet specification guarantees that all
requests will be completely processed before this
method is called
• Override the destroy method when:
You need to release any servlet-specific
resources that you had opened in the init()
method
You need to persist the state of the servlet
public void destroy()
24. ServletsAPI
• Two packages contain the classes and interfaces that
are required to build the servlets .
• These are javax.servlet and javax.servlet.http. They
constitute the core of the Servlet API.
• Keep in mind that these packages are not part of the
Java core packages.
• Therefore, they are not included with Java SE. Instead,
they are provided by Tomcat.
• They are also provided by Java EE.
25. The javax.servletPackage
• This contains a number of interfaces and classes that establish
the framework in which servlets operate
26. The ServletInterface
• All servlets must implement the Servlet interface.
• It declares the init( ), service( ), and destroy( ) methods that
are called by the server during the life cycle of a servlet.
• A method is also provided that allows a servlet to obtain any
initialization parameters.
• These methods are invoked by the server.
• The getServletConfig( ) method is called by the servlet to
obtain initialization parameters.
• A servlet developer overrides the getServletInfo( ) method
to provide a string with useful information (for example, the
version number). This method is also invoked by the server.
28. The ServletConfigInterface
• The ServletConfig interface allows a servlet to obtain
configuration data when it is loaded.
• The methods declared by this interface are summarized here:
34. ProcessingParameters–Hello
Servlet
• We want to create a servlet that takes an user name
as a parameter and says "Hello, <user_name>"
• We need HTML form with a text field
• The servlet can later retrieve the value entered in the
form field
<form method="GET or POST" action="the servlet">
<input type="text" name="user_name">
</form>
String name = request.getParameter("user_name");
40. The javax.servlet.httpPackage
• The classes and interfaces defined in javax.servlet, such as
ServletRequest, ServletResponse, and GenericServlet, will
illustrate the basic functionality of servlets.
• However, when working with HTTP, you will normally use the
interfaces and classes in javax.servlet.http.
41. ServletsAPI
• The most important servlet functionality:
Retrieve the HTML form parameters from the
request (both GET and POST parameters)
Retrieve a servlet initialization parameter
Retrieve HTTP request header information
HttpServletRequest.getParameter(String)
ServletConfig.getInitParameter()
HttpServletRequest.getHeader(String)
42. ServletsAPI
Set an HTTP response header / content type
Acquire a text stream for the response
Acquire a binary stream for the response
Redirect an HTTP request to another URL
HttpServletResponse.setHeader(<name>,<value>)/
HttpServletResponse.setContentType(String)
HttpServletResponse.getWriter()
HttpServletResponse.getOutputStream()
HttpServletResponse.sendRedirect()
43. The CookieClass
• The Cookie class encapsulates a cookie. A cookie is stored
on a client and contains state information. Cookies are
valuable for tracking user activities.
• A servlet can write a cookie to a user’s machine via the
addCookie( ) method of the HttpServletResponse interface.
The data for that cookie is then included in the header of the
HTTP response that is sent to the browser.
• The names and values of cookies are stored on the user’s
machine.
1. The name of the cookie
2. The value of the cookie
3. The expiration date of the cookie
4. The domain and path of the cookie
45. HandlingHTTPRequestsand
Responses
• The HttpServlet class provides specialized methods that
handle the various types of HTTP requests.
• A servlet developer typically overrides one of these
methods. These methods are doDelete( ), doGet( ),
doHead( ), doOptions( ), doPost( ), doPut( ), and doTrace(
).
• However, the GET and POST requests are commonly used
when handling form input. Therefore, this section
presents examples of these cases.
54. SessionTracking
• HTTP is a stateless protocol. Each request is independent of the
previous one.
• However, in some applications, it is necessary to save state
information so that information can be collected from several
interactions between a browser and a server. Sessions provide such
a mechanism.
• A session can be created via the getSession( ) method of
HttpServletRequest.
• An HttpSession object is returned. This object can store a set of
bindings that associate names with objects.
• The setAttribute( ), getAttribute( ), getAttributeNames( ), and
removeAttribute( ) methods of HttpSession manage these bindings.
• Session state is shared by all servlets that are associated with a
client.
55. SessionTracking
public class DateServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Get the HttpSession object.
HttpSession hs = request.getSession(true);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.print("<B>");
Date date = (Date)hs.getAttribute("date");
if(date != null) {
pw.print("Last access: " + date + "<br>");
}
date = new Date();
hs.setAttribute("date", date);
pw.println("Current date: " + date);
}
}
56. SessionTracking
• When you call getSession() each user is automatically
assigned a unique Session ID
• How does this Session ID get to the user?
• Option 1: If the browser supports cookies, the
servlet will automatically create a session cookie,
and store the session ID within the cookie In
Tomcat, the cookie is called JSESSIONID
• Option 2: If the browser does not support cookies,
the servlet will try to extract the session ID from
the URL
57. Problems
1. Create a servlet that prints in a table the numbers
from 1 to 1000 and their square root.
2. Create a servlet that takes as parameters two integer
numbers and calculates their sum.
Create a HTML form that invokes the servlet. Try to
use GET and POST methods.
3. Implement a servlet that plays the "Number guess
game". When the client first invoke the servlet it
generates a random number in the range [1..100]. The
user is asked to guess this number. At each guess the
servlet says only "greater" or "smaller". The game
ends when the user tell the number.
59. JavaServerPage(JSP)
• JSP (Java Server Pages) is server side technology to
create dynamic java web application.
• Allows Java programming code to be embedded in the
HTML pages.
• JSP contains an extension of .jsp
• After execution of a JSP page a plain HTML is
produced and displayed in the client's Web browser.
• JSP can be thought as an extension to servlet
technology because it provides features to easily
create user views.
62. WebContainer
• Web Container translates JSP code into a servlet class
source(.java) file, then compiles that into a java servlet
class.
• In the next step, the servlet class bytecode is loaded using
classloader. The Container then creates an instance of
that servlet class.
• The initialized servlet can now service request. For each
request the Web Container call the jspService() method.
• When the Container removes the servlet instance from
service, it calls the jspDestroy() method to perform any
required clean up.
63. JSPLifeCyclePhases
1. Translation – JSP pages doesn’t look like normal java
classes, actually JSP container parse the JSP pages
and translate them to generate corresponding servlet
source code. If JSP file name is hello.jsp, usually its
named as hello_jsp.java.
2. Compilation – If the translation is successful, then
container compiles the generated servlet source file to
generate class file.
3. Class Loading – Once JSP is compiled as servlet class,
its lifecycle is similar to servlet and it gets loaded into
memory.
64. JSPLifeCyclePhases
4. Instance Creation – After JSP class is loaded into
memory, its object is instantiated by the container.
5. Initialization – The JSP class is then initialized and it
transforms from a normal class to servlet.
6. Request Processing – For every client request, a new
thread is spawned with ServletRequest and
ServletResponse to process and generate the HTML
response.
7. Destroy – Last phase of JSP life cycle where it’s
unloaded into memory.
65. JSPLifecycleMethods
• Once a JSP page is translated to a servlet, the container
invokes the following life cycle methods on the servlet :
1. jspInit() : This method is invoked at the time when the
servlet is initialized.
2. jspService() : This method is invoked when request
for the JSP page is received.
3. jspDestroy() : This method is invoked before the
servlet is removes from the service.
67. JSPTags(Elements)
• EXPRESSION enclosed in <%= and %> markers
A expression is used to insert the result of a Java
expression directly into the output.
• SCRIPTLET enclosed in <% and %> markers:
A scriptlet can contain any number of JAVA language
statements, variable or method declarations, or
expressions that are valid in the page scripting
language.
<%
String message = “Hello World”;
out.println (message);
%>
The time is : <%= new java.util.Date() %>
68. JSPTags(Elements)
• DIRECTIVES syntax - <%@ directive attribute = "value" %>
A JSP directive gives special information about the JSP page to the
JSP Engine.
There are three main types of directive :-
page : processinginformation for this page
include : files to be included
taglib : tag library to be used in the page
69. JSPTags(Elements)
• DECLARATION enclosed in <%! and %> markers
This tag allows the developer to declare variables or
methods.
• Code placed in this must end in a semicolon(;).
• Declarations do not generate output, so are used with
JSP expressions or scriptlets.
77. RequestString
• A browser generate request string whenever the submit
button is selected. The user requests the string consists of
URL and the query the string.
Example of request string:
http://www.jimkeogh.com/jsp/?fname=” Bob” & lname
=”Smith”
• Your jsp program needs to parse the query string to extract
the values of fields that are to be processed by your
program. You can parse the query string by using the
methods of the request object.
• getParameter(Name) method used to parse a value of a
specific field that are to be processed by your program
78. RequestString
• code to process the request string
<%! String FirstName =requst.getParameter(fname);
String LastName =requst.getParameter(lname); %>
• Copying from multivalued field such as selection list field can
be tricky multivalued fields are handled by using
getParameterValues()
• Other than request string url has protocols, port no, the host
name
• Example
<%! String [ ] EMAIL= request. getParameterValues ("EMAILADDRESS ") %>
<P><%= EMAIL [0])%> < / P>
<P><%= EMAIL [1]%> </P>
79. UserSession
• A JSP program must be able to track a session as a client
moves between HTML pages and JSP programs. There are
three commonly used methods to track a session.
• These are
1. by using a hidden field,
2. by using a cookie, or
3. by using a JavaBean,
80. HiddenField
• A hidden field is a field in an HTML form whose value isn't
displayed on the HTML page
• You can assign a value to a hidden field in a JSP program
before the program sends the dynamic HTML page to the
browser.
• A web server can send a hidden HTML form field along with
a unique session ID as follows
<input type = "hidden" name = "sessionid" value = "12345">
• Each time the web browser sends the request back, the
session_id value can be used to keep the track of different
web browsers.