java servlet pages || Servlet with example
Whst is a Servlet ?
Servlet technology is used to create web application , (dwells at server side and produces energetic web page) mostly used with Java.
Servlet is vigorous and versatile since of java dialect. Some time recently serlvel CGI (common portal Interface) scripting dialect was well known as a server side scripting dialect .Bu there was numerous diadvantages of this technology.there numerous course and interfacing in servlet API.such a s Servlet,GenericServllet,Http Servlet,SrevletRequest and ServletResponse etc.
Servlet can be described in many ways depending on the context
- Servlet is a good web technology that is used to craete web applications all the time.
- Servlet is also known as a API that provides classes and interfaces including documentaions.
- Servlet is an interface that must be implemented for creating a servlet class.
- The servlet may be a course that expands the capabilities of the servers and reacts to the approaching requests.it can react to any sort of ask.
- Servlet is the web component that is deployed to the server to create dynamic web page .
Web applications
A web application is an application available from the net . A web application could be a composed of web components like servlet,jsp and channel etc and other component such as HTML (Hyper Content Check Of language).The web components ordinarily executes within the web server and react to the HTTP ask.
Advantages of Servlet
1.better performance : because it creates thread for each request not process.
2.Portability:because it uses java language.
3.Robust:Servlet are managed by JVM(Java Virtual Machine) so no need to worry about memory task.
4.Secure: because it uses java language.
Servlet Phrasing
There are a few key focuses that ought to be know by a servlet software engineer like server.container,get request,post ask etc. Let's to begin with dicuss around these things at that point we are going move to the servlet innovation.
- HTTP(hyper Hypertext Transfer protocal)
- HTTP request types
- Difference between GET and Post method
- Container
- Server and difference between web server and application sever.
- Content Type
- Introduction of XML
- Deployment etc,
HTTP(Hyper Text Transfer protocol)
1..Http is the protocal that permits wev servers and browser to trade information over the net.
2.It is a request and response protocal
3.Http uses reliable TCP connection by default on port 80.
4.It is stateless implies such ask are concidered as the unused request/.In other words server doesn't perceive the client bydefault.
Http Request method
Each ask features a header that tells the status of the client.there are numerous ask methods.GET and POST ask are for the most part utilized in any web application.
The http request methods a re GET,POST,HEAD,PUT,DELETE,OPTIONS,TRACE etc.
Difference between POST and GET Htpp Methods
There many difference between the Get and Post method As you can see bellow.
GET POST
In case of Get request only limited In case of post request large amount of data can be sent
amount of data can be sent because because data is sent in body
data is sent in header
Get request is not secure because post request is secured because data is not exposed in URL
data is uncovered in the URL bar
Get request can be bookmarked Post request cannot be bookmarked
GET request is idempotent means Post request is not idempotent
second request will be ignored until
response of first request is delivered
Get request is more effective and Post request is less effective and less used than the Get used more than Post methos request
Container
It gives runtime environment for JavaEE (j2ee) application
it performs many operations that are given below
1.Life cycle management
2.Multithreaded support
3.Object poling
4.and Scurity
Server
it could be a running program or computer program that gives administrations
There are two types of servers
1.Web servers
2.Application Servers
Life cycle of Servlet
The internet holder keep up the life cycle of a servlet occurrences. Let's see the life cycle of a servlet.
1.Servlet class is loaded
2.Servlet instance is created
3.init method is invoked
4.service method is invoked
4.destroy method is invoked
- As shown within the over chart ,there are three staes of a servlet new,ready, and conclusion state.
- the servlet is in new state id servlet instance is created
- After invoked the inti method .Servlet comes in the ready state .
- essentially within the prepared state the servlet performs all the tasks.When the net holder conjured the devastate strategy it shifts to the conclusion state.
Steps
i.Servlet class is loaded
The class loader is mindful for stacking the Servlet class.The servlet class is stacked when the primary ask for the server is gotten by the net container
ii.Servlet instance is created
The web container creates the instance of a servlet after loading a servlet class .The servlet instance is created only once .
iii.init method is invoked
the web container class the init strategy as it were once after making the servlet instance. The init strategy utilized to initialize the servlet .it is the life cycle method of javax,servlet.Servlet interface .
Syntax :
publicvoidinit(ServletConfig config) throwServletException
iv.Service method is invoked
The web container calls the service strategy/methd each time when ask for the servlet is gotten. On the off chance that servlet isn't initialized ,It follows the primary 3 steps as portrayed over at that point calls the service strategy .In the event that servlet is initialized it call the service methid.Notice the servlet is initialized as it were once .
syntax of the service method of the service interface below
publicvoid service(ServletRequest request , ServletResponse response ) throwsServletException,iOException
v.Destroy method is invoked
The web container calls the devastate strategy some time recently evacuating the servlet occasion from the service . it gives the servlet and opportunity to clean up any resouce for case memory and thread etc
Synatx for the destroy method of the servlet interface
publicvoiddestroy()
Thanks for visiting our site any query or question plz comment bellow or contact us .
Tags:
java