Difference between ServletContext and ServletConfig ?
What is the Difference between ServletConfig and ServletContext.?
ServletConfig:
public interface ServletConfig
ServletConfig encapsulates servlet configuration and gives access to the application (servlet context) object. Servlet initialization parameters appear in the servlet configuration file. Each servlet class may have several different servlet instances, one for each servlet parameters:
- One ServletConfig per servlet
- It is used to pass deploy-time info to servlet and configured in the deployment descriptor file.
- it is used to access ServletContext
- It is within the Servlet element in Deployment descriptor.
- It is accessed by using getServletConfig().getInitParameter("myname");
- It is available only to the servlet in which init-param is configured.
Example:
ServletContext:
public interface ServletContext
ServletContexts encapsulate applications. Applications are generalized virtual hosts; a URL prefix defines a distinct application. So /myapp and /yourapp could define different applications. As a degenerate case, each virtual host has its own ServletContext.
- It returns the current context of a web application running in a particular JVM..
- If the web application is distributed,it is one per JVM.
- It is used to access the elements configured in deployment descriptor.
- It is accessed by using getServletContext().getInitParameter("myname");
- It is available to any servlet or jsp that is part of web application.
Example:
Procedure to Develop a web based Application:-
Create
a folder who’s folder name must be project name (there should not spaces).
Note: we call this folder as project context/web context.
1) Inside the above created folder we create a folder
with the name "WEB-INF"
(must be write in the capital letters only) .Inside the "WEB-INF" create the "classes"
and "lib" folders.
2)
Create
a file whose file name must be “web.xml” (inside WEB-INF)
1)
By
using java we can develop both static and dynamic web-based applications
2) We
can develop two types of web-based applications. They are:
2.1) Static web-based Apllications
2.2) Dynamic web-based Applications
3) What are static web-based applications?
When the client send the request to
the server, if the server is sending same output for multiple times. Then we
call as static web-based applications. To develop static web-based application
we use HTML, java script and images.
4) What
are dynamic web-based applications?
If the output is getting change the
every time we call the applications as dynamic web-based applications we use
servlets, JSP’s to develop dynamic web-based applications.
“ 5) WEB-INF”
folder is called as a “private” folder this is because the file in this folder
can be accessible only by the server.
6) web.xml file is called as “Deployment descriptor”.
7) All the html files of our project must be placed
inside “project and outside WEB-INF” folder.
8)
Once
if we are ready with the project, we must deploy the project.
9) what is the meaning of deployment?
Placing the project in a server specified folder is called as deployment
10) By
default tomcat server uses 8080 port number in tomcat we use webapps
folder as the Deployment folder.
11) To
deploy a project it’s the recommended to starts the server and place the
project in webapp (deployment) folder
http://localhost7001/IBM/one.html or
web.html
|
12) To deploy a project in weblogic server we use a folder
auto deploy (weblogic server).
13) Most
of the times we need to read deploy the project in the server.
DELETE(): This method is used to delete the resource from server.
Because of
security reasons non of the server supports this methods.
TRACE
AND LOCATE(): These methods are used to search for the files inside the
server. Because of the security reasons none of the server vendors supports
these
methods.
What is the difference b/w GET and POST methods?
In case of get() method request the
data will be appended to url and send to server. Who’s as from the post request
the data will be appended to request body. It’s not recommended to use get() to
transfer sensitive data. This is a limitation of 1024Kb size
to transfer the data by using get() method. This is no limitation of
transferring the data by using post() method.
Put() method is used to place a resource into server. Because of
security reason nun of the server supports this method.
Get(): This is the default method send by client to server. When the server
receives the get request server process the request and send the response to
client. In case of get request if the client
want to send the data to server. The data gets appended to URL and it will be send
to server.
Ex:
. . . GET /two.html?uname=raju&pwd=xyz HTTP/1.1
POST(): Post() method is also used to execute the resource in the
server. When we use post request the browser
capture the data and the add it to request body and send to server.
Ex:
post /two.html HTTP/1.1
Accept-language: en-us
uname=raju&pwd=mypassword
Servlets:-
The technologies likes SERVLETS and JSP(java server program)
are used to developed web based applications.
By using java we can develop the following fair types of
applications.
1. Standalone applications
2. Web based applications
3. Applets applications
4. Mobile applications
All the applications which we have developed as of know
standalone application. Standalone application will have a “main()” method.
Standalone applications run on their own. They are dependent
on other program. Where as web based application are dependent on “Servers”.
Disadvantages:
A.
As
the standalone application Run’s on client computer we need to install it in
all the computers.
B.
We
will have lout of maintained related problems as part of the project. That is
when ever to change the project we have placed with in all the client
computers.
C.
A
Standalone application consumes the resources of client computer (Hard disk,
Processor and etc).
D.
Standalone
applications are person independent only some fellows know how to install and
settings the required configuration.
E.
To
develop the web based applications meagerly two programs are required.
1.
Server
2.
Client
F.
The
client sent to request the server takes the request and processes it sent the
response to client.
A. They are so many server software’s
are available some of then on weblogic, tomcat, websphere, jboss, resign and
glash fish etc.
B. They are so many client software’s
are available some of then on IE, chrome, firefox, opera, safari and netscape
etc.
C. As a developer we are responsible to
develop a program which Run’s inside the server.
D. To develop the web based applications
we required “http” protocol. (Server and client those are same Protocol using
with http)
E. http protocol is devided into two
parts. They are:
1. http Request format
2. http Response format
The following are http Request format and Response
format
No comments:
Post a Comment