1. What is JSE?
Java Standard Edition (JSE) is core java, which is used to develop standalone applications e.g. calculator.
2. What is JEE?
Java Enterprise Edition (JEE) is used to create standalone/web applications e.g. facebook, gmail. The main technologies in JEE are:
JDBC: in Java Database Connectivity, we perform select, insert, update, and delete operations. It is standalone application.
Servlet: –we can develop standalone web applications.
JSP: in Java Server Pages, web applications are developed.
3. What is servlet?
By using servlet, we develop web applications.
Static web applications: fixed data e.g. about us, contact us, home page. Dynamic web applications: it will change data. Based on our actions, its data will be changed. E.g. Google search.
4. What are the types of web pages?
Static web pages: display fixed content for all the requests. E.g. about us page, terms and condition page, contact us page etc.
Dynamic web pages: the content of web page changes based on the time of request generation or based on the input values of request. E.g. live game scores page, Gmail inbox page etc.
• Static web components (generates the static web page) e.g. THML pages.
• Dynamic web components (generates the dynamic web page) e.g. servlet, jsp, asp.net, php components.
5. What is web server?
The execution of standalone application takes place only initiate the execution. The web component of web application will be executed automatically and dynamically in automated environment. The moment they are requested from browser for this automation we need special software called web server software. Here we use Tomcat 9 as a server. The web server is special software that listens to client requests continuously, takes the request from client passes the request to appropriate web component, executes the web component dynamically and sends the output to browser as response in the form of web page. E.g. Tomcat, IIS (Internet Information Server), Apache Web Server (AWS).
6. What is java servlet?
Java servlet is generic server extension that means a java class can be loaded dynamically. To expand the functionality of a server. Servlets are used with web servers run inside a java virtual machine on the server so those are safe and portable.
7. What is servlet container?
A servlet container is nothing but a compiled, executable program. The main function of the container is to load, initialize, and execute servlet.
8. What are the types of servlet container?
There are two types of servlets.
A simple servlet container is not fully functional and therefore it can only run very simple servlet, and does the following:
• Wait for Http request.
• Construct ServletRequest object and ServerResponse object.
• If request is for a static resource, invoke the process method of the StaticResourceProcessor instance, passing the ServletRequest and ServletResponse objects.
• If request is for a servlet, load the servlet class and invoke its service method, passing the _______.
A fully functional servlet container additionally does the following for each http request servlet:
• When the servlet is called for first time, load the servlet class and call its init method.
• For each request, construct an instance of java.servlet.ServletRequest and an instance of javax.ServletResponce.
• Invoke the servlet’s service method, passing the ServletRequest and ServletResponse objects.
• When the servlet class is shut down, call the servlet’s destroy method and unload the servlet class.
9. Based on the physical location, how many types of containers are there?
• Standalone container: here container and web server are together comes as a single software service.
• In process container: here container comes as separate software service inside the web server software. E.g. servlet container/jsp container to tomcat server.
• Out of process container: here container resides server software service but will be linked with web server software. E.g. servlet container/jsp container that is linked with IIS server to execute java web application in IIS.
10. What are the responsibilities of web server?
• Lister to client requests continuously by starting demon process.
• Takes the requests and passes the request to container.
• Provides container to execute server side web comps.
• Gives middleware services.
• Provides environment do deploy, manage and un-deploy the web applications.
• Gathers output given by webcoms and sends those outpouts to browser as response.
11. What are the responsibilities of containers?
• Take the request from server and passes to appropriate web component.
• Execute server side web component.
• Enables the communication between multiple web components.
• Passes the output of web component to web erver.
12. What are the advantages of java servlet?
• Portability
• Powerful
• Efficiency
• Safety
• Integration
• Extensibility
• Inexpensive
Servlet 2
Download and setup Tomcat 9 software.
First servlet application:
• When you make any application, you need to implement from Servlet Interface.
• Whenever we develop web application, we need two objects: request and response objects.
• In web application, we need to give request. Based on request, it generates response.
• Servlet is predefined servlet interface. All classes and objects we use here are available in servlet API.
• Interface and class inheritance: implements. Interface and interface or class and class: extends.
• Servlet has five methods:
• What is generic servlet (abstract class)?
• What is concrete and abstract class?
• _______.
13. What are the five steps _______?
• Create and extend your class to HttpServlet
• Override service method
• Set content type to text/html
• Get printwriter object
• Print some message
• Configure web.xml file (inside servlet, name and class; inside servlet mapping, name and pattern)
• Close
Lab 1:
Create a simple servlet program to display welcome message.
Servlet 3
(download tomcat 9)
(Eclipse downloaded in 8:20)
(Start in 27.4)
• How to configure tomcat in eclipse?
Window => preferences => server => runtime environments => add = Apache Tomcat v9.0 => next => browse the location
(Start from 10 minutes)
• If you are developing any program, you need to implement from servlet interface.
• Whenever we develop web application, we need two objects: request object and response object. We need to give a request. Based on request, it generates response.
• Servlet is predefined interface. All classes are available in servlet API.
• Inheritance: between two classes => extends, between two interface => extends, between class and interface => implements.
1. How many methods are available in servlet interface? Name all.
Five methods are available. https://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/Servlet.html (12.50). These are: _______
2. What is difference between class, interface, and abstract class?
Interface: we can declare method, but we cannot implement. Abstract class: both concrete (method with body) and abstract (method without body) methods are there. We cannot write logic. Class: we can write concrete class only.
3. What is genericServlet?
It is an abstract class. _______ Overloading, overriding, super class,
it does not support http protocol
4. What is httpServlet class_______?
It is abstract class. It has two services methods and seven do get _______ methods.
(Serlet(t) GenericServlet(ac), HttpServilet(ac)
• Step 1: Extend you class from HttpServlet.
• Step 2: override service method
• Step 3: set content type
• Step 4:
• Step 5:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// 1. Create serlet class extending from servlet
public class ServletExample1 extends HttpServlet {
public static void main(String []args){
// 2. Override service method
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws servletException() {
// 3. Set content type
res.setContentType("text/html");
// 4. Get printwriter object
PrintWriter pw=res.getWriter();
// 5. Print some message with html tags
pw.println("
ServletExample1")
System.out.println("ServletExample1");
}
}
}
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// 1. Create serlet class extending from servlet
public class ServletExample2 extends HttpServlet {
public static void main(String []args){
// 2. Override service method
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws servletException() {
// 3. Set content type
res.setContentType("text/html");
•
• // 4. Get printwriter object
• PrintWriter pw=res.getWriter();
•
• // 5. Print some message with html tags
• pw.println("