How to Create Java Servlet Application
How to Create Java Servlet Application
https://dotnettutorials.net/lesson/first-java-servlet-application/ 1/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
ServletConfig
Interface 1. How to Create Java Servlet Application
https://dotnettutorials.net/lesson/first-java-servlet-application/ 2/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
Java Servlet 5. What happens if the programmer calls destroy() method explicitly from the service(-,-)
Attributes method of the servlet program?
6. What happens if the programmer calls the init(-) method explicitly from the service(-,-)
Develop a Java Web Application to Implement the use case of the Addition of two
numbers.
Java Servlets –
Advanced Please have a look at the following diagram to understand what we are going to develop.
https://dotnettutorials.net/lesson/first-java-servlet-application/ 3/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
HttpSession Session
Tracking Mechanism <web-app>
https://dotnettutorials.net/lesson/first-java-servlet-application/ 4/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
AdditionServlet.java
importjavax.servlet.*;
import java.io.*;
public class AdditionServlet extends GenericServlet
Real-time Application {
Development Examples public void service (ServletRequest request,ServletResponse response) th
Registration Form in {
Servlet
String a = request.getParameter ("T1");
Fetch Data from String b = request.getParameter ("T2");
Database using
int n1 = Integer.parseInt (a);
Servlet
int n2 = Integer.parseInt (b);
Improving Servlet
int sum = n1 + n2;
performance to fetch
response.setContentType ("text/html");
records from
PrintWriter out = response.getWriter ();
database
out.println ("<!DOCTYPE html>");
Uploading and
Downloading Files in out.println ("<html>");
https://dotnettutorials.net/lesson/first-java-servlet-application/ 5/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
https://dotnettutorials.net/lesson/first-java-servlet-application/ 6/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
Advertisements
out.println(” “); This method makes the stream object i.e. out for writing the data to the destination object
response. This response object passes that data (argument values of println() method) to the webserver
and the webserver writes data to the browser window as an HTTP response in the form of a web page.
https://dotnettutorials.net/lesson/first-java-servlet-application/ 7/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
out.close(); This method is used to close the stream connection with the response object.
1. Servlet program execution is taken care of by servlet containers through life cycle methods.
2. Since the main(-) method is not the life cycle method of the servlet program so it is not called by the
servlet container.
3. Only in the stand-alone application, do we need the main(-) method to begin the application
execution.
4. The container software managed the programs or components that will be executed through life
cycle methods. So the main(-) method is not required in that components or programs.
1. The stand-alone application that will be executed by JVM directly needs to have the main method
to begin the execution. Since the servlet program is not a standalone application and it is a web
https://dotnettutorials.net/lesson/first-java-servlet-application/ 8/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
resource program that will be executed by servlet containers through life cycle methods so there is
no need for the main method in the servlet program.
2. If an already running java application wants to create certain other java class objects and wants to
call a method of that class then that other class needs not to have a main(-) method.
3. A Servlet container is a continuously running java application/software which creates our own
servlet class object and calls life cycle methods on that object for executing the servlet program. So
our servlet program needs not to have a main(-) method.
4. Since we never give our servlet program to JVM directly for execution so there is no need of
placing the main(-) method in our servlet program.
What happens if the programmer calls destroy() method explicitly from the
service(-,-) method of the servlet program?
The Servlet container will not destroy our servlet class object but the logic of the destroy method execute
along with the service method. When the life cycle event is raised the servlet container calls the life cycle
method. Since the programmer has called the life cycle method, automatically the servlet container never
raises the life cycle event.
What happens if the programmer calls the init(-) method explicitly from the
service(-,-) method of the servlet program?
The Servlet container never creates a new object of our servlet class for the above call but the logic of the
init(-) method executes along with the service method.
What is Specification?
https://dotnettutorials.net/lesson/first-java-servlet-application/ 9/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
A specification is a document or reference that contains a set of rules and guidelines to develop the
software. There are two types of specifications
1. Open specification: (Anyone can develop software based on this specification) example: JDBC
specification, Servlets specification, JSP specification, etc.
2. Proprietary Specification: (The only specific company which has given specification is allowed to
develop the software). Example: .net specification
When the website is under development /testing in a software company then it is called a web application.
Once a web application is hosted on the internet by purchasing a Domain name (www.dotnettutorials.net)
and space internet network is called a website.
What are static web resource programs and dynamic web resource programs?
Static web resource programs generate static web pages. For example, HTML Pages. Dynamic web
resource programs generate a dynamic web page. Example Servlet program, JSP Program, etc. The
static web page contains fixed content forever, the content of the dynamic web page changes based on
the input values of the request.
Advertisements
https://dotnettutorials.net/lesson/first-java-servlet-application/ 10/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
1. We can identify whether a web resource program is client-side or server-side based on the place
where the web resource programs are executing.
2. If the web resource programs are executing on the server then they are called a server-side web
resource program. For example, the servlet program, JSP program, etc.
3. If the web resource program comes to the browser window from the web application for execution
then it is called a client-side web resource program. Example: HTML programs, javascript
programs.
4. Both client-side and server-side web resource programs are residing on a web server only.
5. The process of keeping the web application in the webserver is technically called deployment and
the reverse process is called un-deployment.
https://dotnettutorials.net/lesson/first-java-servlet-application/ 11/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
In the next article, I am going to discuss How does the Servlets work in detail. Here, in this article, I try to
explain How to Create Java Servlet Application. I hope you enjoy this How to Create Java Servlet
Application article.
https://dotnettutorials.net/lesson/first-java-servlet-application/ 12/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has
very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET
Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud
Computing, Microservices, Design Patterns and still learning new technologies.
https://dotnettutorials.net/lesson/first-java-servlet-application/ 13/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
Leave a Reply
Your email address will not be published. Required fields are marked *
https://dotnettutorials.net/lesson/first-java-servlet-application/ 14/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
Comment *
Post Comment
https://dotnettutorials.net/lesson/first-java-servlet-application/ 15/16
3/26/24, 12:00 PM How to Create Java Servlet Application - Dot Net Tutorials
About Us Privacy Policy Contact ADO.NET Tutorial Angular Tutorials ASP.NET Core Blazor Tuturials ASP.NET Core Tutorials
ASP.NET MVC Tutorials ASP.NET Web API Tutorials C Tutorials C#.NET Programs Tutorials C#.NET Tutorials Cloud Computing Tutorials
Data Structures and Algorithms Tutorials Design Patterns Tutorials DotNet Interview Questions and Answers Core Java Tutorials
Entity Framework Tutorials JavaScript Tutorials LINQ Tutorials Python Tutorials SOLID Principles Tutorials SQL Server Tutorials Trading Tutorials
JDBC Tutorials Java Servlets Tutorials Java Struts Tutorials C++ Tutorials JSP Tutorials MySQL Tutorials Oracle Tutorials
ASP.NET Core Web API Tutorials HTML Tutorials
https://dotnettutorials.net/lesson/first-java-servlet-application/ 16/16